Posted by big_smile on December 28, 2012 at 3:18pm
Drupal's FORM API lets you specify Form States. These have a handy visibility state that let you show/hide parts of a form depending on which fields have been filled in. It's a good way of reducing clutter on a form.
For my form, I only want it to be visible, it the user has NOT selected an option on the proceeding form.
How can I do this?
I have posted my code below:
$form['buttons_style'] = array(
'#type' => 'select',
'#title' => t('Button Style'),
'#options' => array(
'none' => t('Default Style'),
'style1' => t('Style 1'),
'style2' => t('Style 2')
),
'#default_value' => (isset($style_settings['buttons_style'])) ? $style_settings['buttons_style'] : 'none',
'#description' => t('Select a button style')
);
This is my Form: I only want it visible if the user has NOT selected 'none' in the above $form['buttons_style']
$form['buttons_height'] = array(
'#type' => 'select',
'#title' => t('Button sizes'),
'#options' => array(
'-small => t('Small'),
'-medium' => t('Medium'),
'-tall' => t('Tall')
),
);
Comments
See
See http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_p..., you could use a state of 'invisible'.
Thank you! That is wonderful!
Thank you! That is wonderful! I didn't realise that invisible could be used in the way I wanted it to.