1

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?

1 Answer 1

4

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),
      ),
    ),
  );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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