Hi, I have drupal 5.2 installed, and I wanted to find out what the php format would be for a radio button consisting of two choices.

Here's some code I have so far, but it only shows up as one options. Thanks

You should only be allowed to pick either Personal Need or Business Need but not both. The title of the radio button will be "What is this for?"

 $form['needs'] = array( 
'#type' => 'radio', 
'#title' => t('What is this for?'), 
'#value' => 'p', 
'#values' => array( 'p' => 'Personal Need', 'b' => 'Business Need'), 
'#required' => TRUE 
);

Comments

merkurio’s picture

This should work

$opciones = array( 'p' => 'Personal Need', 'b' => 'Business Need');

 $form['needs'] = array(
'#type' => 'radio',
'#title' => t('What is this for?'),
'#value' => $opciones, // here ther is the array.
'#required' => TRUE
);
nevets’s picture

Your close, the line
'#values' => array( 'p' => 'Personal Need', 'b' => 'Business Need'),
should read
'#options' => array( 'p' => 'Personal Need', 'b' => 'Business Need'),

merkurio’s picture

nevets, you're right, I copy&paste and don't saw that. Sorry for the mistake

mooffie’s picture

and #type should be 'radios', not 'radio'.

hello12345’s picture

Thank You!