Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.