-1

I'm looking for a way to render a form with 2 text-fields in to the same (for each) line. I would like to do this using hook functions, so I tried with this:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'form_page_1') {
    $form['#type'] = 'table';
  }
}

But obviously it doesn't work. Do you have any idea?

6
  • You have to place the form elements in the table, see drupal.stackexchange.com/questions/185032/…
    – 4uk4
    Jul 11, 2018 at 15:17
  • 1
    Why not use CSS?
    – Beebee
    Jul 11, 2018 at 15:17
  • if ($form_id = 'form'page'1') { is wrong. It needs to be if ($form_id == 'form'page'1') {. Next thing 'form'page'1' is wrong. It probably needs to be 'form_page_1' or something else.
    – leymannx
    Jul 12, 2018 at 10:39
  • @leymannx sorry it is not a copy and paste of the original code
    – que le
    Jul 12, 2018 at 15:27
  • 1
    It should be the exact code so people can assist.
    – Kevin
    Jul 12, 2018 at 15:40

1 Answer 1

0

Can you just add wrapper to each field with bootstrap classes to both form elements?

    $form['field_1_wrapper'] = array(
      '#type' => 'container',
      '#attributes' => array('class' => array('col-sm-6')),
    );

     $form['field_1_wrapper']['field_1'] = array(
      '#type' => 'textfield',
      '#title' => t('Field 1'),
    );

    $form['field_2_wrapper'] = array(
      '#type' => 'container',
      '#attributes' => array('class' => array('col-sm-6')),
    );

    $form['field_2_wrapper']['field_2'] = array(
        '#type' => 'textfield',
        '#title' => t('Field 2'),
    );
1
  • I don't have access to the form src; i can modify only ".module" and "css" files
    – que le
    Jul 17, 2018 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.