Forum Moderators: coopster
I'm trying to create two simple php radio buttons but I'm not having any luck. I'm trying to create the two buttons so that only one choice can be made.
Since, the form I'm using has a specific format, I tried integrating the radio buttons in but when you click on the radio buttons, both selections can be made, and you can't "uncheck" the buttons once they have been made.
The choices are either a "Personal Need" or a "Business Need"
Any help is appreciated
$form['needs1'] = array(
'#type' => 'radio',
'#title' => t('Personal Need'),
'#size' => 20,
'#value' => 0,
'#values' => array( 0 => 'no', 1 => 'yes'),
'#required' => TRUE
);
$form['needs2'] = array(
'#type' => 'radio',
'#title' => t('Business Need'),
'#size' => 20,
'#value' => 0,
'#values' => array( 0 => 'no', 1 => 'yes'),
'#required' => TRUE
);
<div class="form-item">
<label class="option"><input type="radio" name="needs1" value="" class="form-radio required" /> Personal Need</label>
</div>
<div class="form-item">
<label class="option"><input type="radio" name="needs2" value="" class="form-radio required" /> Business Need</label>
</div>
<div class="form-item">
<label class="option"><input type="radio" name="needs" value="1" class="form-radio required" /> Personal Need</label>
</div>
<div class="form-item">
<label class="option"><input type="radio" name="needs" value="2" class="form-radio required" /> Business Need</label>
</div>
In the output, the value still shows up with neither a 1 or 2 even after changing it to a 1 or 2 in the php.
<div class="form-item">
<label class="option"><input type="radio" name="needs" value="" class="form-radio required" /> Business Need</label>
</div>
$form['needs'] = array(
('#type' => 'radio',
'#title' => t('Personal Need'),
'#size' => 20,
'#value' => 0,
'#values' => array( 0 => 'no', 1 => 'yes'),
'#required' => TRUE ),
('#type' => 'radio',
'#title' => t('Business Need'),
'#size' => 20,
'#value' => 0,
'#values' => array( 0 => 'no', 1 => 'yes'),
'#required' => TRUE)
);
I'm going to take a stab at it and give you this code:
$form['needs'] = array(
'#type' => 'radio',
'#title' => t('What is this for?'),
'#value' => 'p',
'#values' => array( 'p' => 'Personal Need', 'b' => 'Business Need'),
'#required' => TRUE
);
But your best bet is to read the API's documentation on creating radio buttons.