I have a form that has 5 radio buttons. Two of those have optional additional parameters that the user can select. If radio 1 is selected, then only the optional items for that radio would make sense to be populated. Is there a way using the Forms API to accomplish this?
I have the following code. The Optionals Extra2 is the olnly select boxes that are shown. If I change the $form['mc']['cats']
to $form['mc']['cats2']
I can get it to display but it's not in the same fieldset as the rest.
$form['mc'] = array(
'#type' => 'fieldset',
'#title' => t('Membership Categories (select only one)'),
);
$form['mc']['cats'] = array(
'#type' => 'fieldset',
'#title' => FALSE,
'#prefix' => '<div style="background-color:red;">',
'#suffix' => '</div>',
);
$form['mc']['opts'] = array(
'#type' => 'fieldset',
'#title' => FALSE,
);
$membership_cats = array(
0 => t('Option 1'),
1 => t('Option 2'),
2 => t('Option 3'),
3 => t('Option 4'),
4 => t('Option 5'));
$form['mc']['cats']['profile_memberlist']['field_membership_category']['#prefix'] = '<div style="background-color:salmon;float:left;width:50%;">';
$form['mc']['cats']['profile_memberlist']['field_membership_category']['#suffix'] = '</div>';
$form['mc']['cats']['profile_memberlist']['field_membership_category']['#type'] = 'radios';
$form['mc']['cats']['profile_memberlist']['field_membership_category']['#title'] = t('Membership Category');
$form['mc']['cats']['profile_memberlist']['field_membership_category']['#description'] = t('Please select your membership category.');
$form['mc']['cats']['profile_memberlist']['field_membership_category']['#options'] = $membership_cats;
$optionals = array(
0 => t('No Thanks'),
1 => t('Optional 1'),
2 => t('Optional 2'));
$optionals2 = array(
0 => t('No Thanks'),
1 => t('Optional 3'),
2 => t('Optional 4'));
$form['mc']['cats']['profile_memberlist']['field_optional_extras']['#type'] = 'select';
$form['mc']['cats']['profile_memberlist']['field_optional_extras']['#prefix'] = '<div style="background-color:lime;">';
$form['mc']['cats']['profile_memberlist']['field_optional_extras']['#suffix'] = '</div>';
$form['mc']['cats']['profile_memberlist']['field_optional_extras']['#title'] = t('Optional Extras');
$form['mc']['cats']['profile_memberlist']['field_optional_extras']['#options'] = $optionals;
$form['mc']['cats']['profile_memberlist']['field_optional_extras']['#type'] = 'select';
$form['mc']['cats']['profile_memberlist']['field_optional_extras']['#prefix'] = '<div style="background-color:lime;">';
$form['mc']['cats']['profile_memberlist']['field_optional_extras']['#suffix'] = '</div>';
$form['mc']['cats']['profile_memberlist']['field_optional_extras']['#title'] = t('Optional Extras2');
$form['mc']['cats']['profile_memberlist']['field_optional_extras']['#options'] = $optionals2;