How to add horizontal form elements?

Answered

I am getting that every element is located under the previous one. I need to describe the form where all elements will be placed horizontally but not vertically.

Phillip Ruiz Asked on October 21, 2015 in Drupal.
Add Comment
1 Answer(s)
Best answer

You can try with the following code which is used by the Node module:

// Build the 'Update options' form.

$form['options'] = array(

'#type' => 'fieldset',

'#title' => t('Update options'),

'#attributes' => array('class' => array('container-inline')),

'#access' => $admin_access,

);
// ...
$form['options']['operation'] = array(

'#type' => 'select',

'#title' => t('Operation'),

'#title_display' => 'invisible',

'#options' => $options,

'#default_value' => 'approve',

);

The key is the line settings the "#attributes" attribute to "container-inline."
That code is for Drupal 7; the equivalent code for Drupal 6 starts with the following code:
$form['options'] = array(

'#type' => 'fieldset',

'#title' => t('Update options'),

'#prefix' => '<div class="container-inline">',

'#suffix' => '</div>',

);

The key is the line settings the “#attributes” attribute to “container-inline.”

Also, keep in mind that this code is valid for Drupal 7.

Gregory Specter Answered on October 21, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.