0

I have created a form, though I'm having an issue with using the prefix and suffix to place items into rows rather than the list they appear as standard.

For example I have these 3 form elements, how would I go from having them appear as standard on a new line, to on the same line. Normally I would just chuck them into a table and place each one in a different column. I have read that I should possibly use floats?

I have tried '#prefix' => '<div style="float: left; width 200px;">',

'#suffix' => '</div><br>' , But this seems to affect the navigation on the left and shuffle it down.

$form['orange'] = array(
    '#type'=>'select',
    '#title' => t('Select Orange'),
    '#options' => $Orange,
    '#multiple' => false,
    '#prefix' => ,
    '#suffix' => ,
    '#attributes'=>array('size'=>0),
    '#required' => TRUE,
);
$form['apple'] = array(
    '#type'=>'select',
    '#title' => t('Select apple'),
    '#options' => $apple,
    '#multiple' => false,
    '#prefix' => ,
    '#suffix' => ,
    '#attributes'=>array('size'=>0),
    '#required' => TRUE,
);
$form['strawberry'] = array(
    '#type'=>'select',
    '#title' => t('Select strawberry'),
    '#options' => $strawberry,
    '#multiple' => false,
    '#prefix' => ,
    '#suffix' => ,
    '#attributes'=>array('size'=>0),
    '#required' => TRUE,

);

I cannot answer for 7 hours but here it is:

The solution was to close the DIV, I had forgotten, which meant the styling was effecting the whole page.

     '#prefix' => '<div style="float: left; width 200px;">',
    '#suffix' => '</div><br style="clear: left;" /></div>',
    [Useful link to aligning form elements horizontally][1]
0

I think you want to keep it in table. Lets try with putting it in one like this --

$form['orange'] = array(
    '#type'=>'select',
    '#title' => t('Select Orange'),
    '#options' => $Orange,
    '#multiple' => false,
    '#prefix' => '<table><tr><td>',
    '#suffix' => '</td>',
    '#attributes'=>array('size'=>0),
    '#required' => TRUE,
);
$form['apple'] = array(
    '#type'=>'select',
    '#title' => t('Select apple'),
    '#options' => $apple,
    '#multiple' => false,
    '#prefix' => '<td>',
    '#suffix' => '</td>',
    '#attributes'=>array('size'=>0),
    '#required' => TRUE,
);
$form['strawberry'] = array(
    '#type'=>'select',
    '#title' => t('Select strawberry'),
    '#options' => $strawberry,
    '#multiple' => false,
    '#prefix' => '<td>',
    '#suffix' => '</td></tr></table>',
    '#attributes'=>array('size'=>0),
    '#required' => TRUE,

);

I haven't tested this code, so please try this & let me know if it works :)

|improve this answer|||||
0

Yes. We can put the form and form elements into table with rows, columns structure. And of course we can use the prefix and suffix attribute to do that. Please follow this instruction from this Drupal 7: theming forms with tables

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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