Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a form with three form elements:

  1. '#type' => 'radios' element having two options (Yes or No),
  2. '#type' => 'submit' &
  3. '#type' => 'checkbox'

When the user lands on the form page, he should only see the radios element first and can see the checkbox & submit elements only if he selects an option from radios element.

Is there a Drupal way to do this using the Form API?

share|improve this question
up vote 4 down vote accepted

You can use #states attribute in form api to hide submit button and check box

For Example

$form['email_canceled']['settings'] = array(
    '#type' => 'container',
    '#states' => array(

      // Hide the settings when the cancel notify checkbox is disabled.

      'invisible' => array(

       ':input[name="email_canceled_toggle"]' => array('checked' => FALSE),
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.