GRRRRRRR,

Ok, the new form API is cool and all, But im really having a pain displaying and editing this stuff.

Here it goes....
$form['easiness'] = array(
'#type' => 'radios',
'#title' => t('Easiness 1-5'),
'#options' => array('','','','',''),
'#required' => TRUE,
);

That outputs 5 radio buttons one on top of the other (vertically). I need them all to be horizontal. Then, the first radio button has a value of "0", the next "1", etc. I need the radio buttons to start from 1 and go to 5.

Also, when i do...

$output = drupal_get_form('test_page', $form);
return $output;

That prints all the things in the $form array...BUT... how come it shows them with

tags? How can I make it so its just the line and nothing else.

Please help, im lost!

Comments

johnhanley’s picture

You need to properly define your options array.

I'm confused though. Do you mean something like this:

array('0' => '1', '1' => '2', '2' => '3', '3' => '4', '4' => '5');

where '0' is the value and '1' is the label and so on. Season to taste.

The form API will loop through and output the radio buttons accordingly.

I believe there is a method for controlling the output format. Check drupaldocs.org.

chupcha’s picture

ok, so i used array('1' => '', '2' => '', '3' => '', '4' => '', '5' => ''),

cause i didnt need the labels.

But i cant find how to make them horizontal in drupaldocs.org thats why i posted here. Thanks for the help bacteria man

johnhanley’s picture

I think theme_radios is what you're looking for.

djpinoy’s picture

Hey Chupcha,

Yeah - even with the theming functions, I'm not sure there's a way to do this either. The hack I found was to just manually create the radio buttons using regular markup, kinda like this:

          $form['step4'][$i]['package_radio1'] = array (
           '#value' => t('<td><div class="form-item"><center><input type="radio" name="step4[' . $i . '][package]" value="1" class="form-radio" onChange="Javascript: updateTotal();" /></center></div></td>'),
           );

This made a radio button that I could access in the next step through:

$form_values['step4'][$i]['package']

I'm already using Drupal 5.1... are there any plans to add this functionality to a future version of the Form API?

denisanokhin’s picture

You can add the following properties:
'#prefix' => '

',
'#suffix' => '

',

So your element definition will be:
$form['easiness'] = array(
'#type' => 'radios',
'#title' => t('Easiness 1-5'),
'#options' => array('','','','',''),
'#required' => TRUE,
'#prefix' => '

',
'#suffix' => '

',
);

Due to CSS definition of class "container-inline" your radios will be rendered horizontally.

Hope this helps

akaash19’s picture

Hi guys..
even i am facing the same issue.i want to display my radio buttons in same line.
unable to get how..
:(

akaash19’s picture

Hi guys..
I recently came to know that we can give prefix with '#prefix' => '

', and '#suffix' => '

', and you get radio buttons in a line, not vertically aligned.For me it worked.

so the code for radio button looks like:

  $form['options'] = array(
    '#type' => 'radios',
    '#options' => array( '1'=> t('Yes'),'0' => t('No')),
    '#title' => t('my radio'),
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
  );