Switch the visibility of a form element dependent on a checkbox

Public

Hey ho everybody and thank you for viewing my code Snipp.

With this you can hide and show form elements like this text field until the checkbox is checked.
If you want to hide more elements at one time just show and hide a fieldset.

Get raw version
php
  1. $form['nodifi']['check'] = array(
  2. '#type' => 'checkbox',
  3. '#title' => t('Check me and you will get what you deserve'),
  4. );
  5. $form['nodifi']['message'] = array(
  6. '#type' => 'textfield',
  7. '#title' => t('Now you can see me'),
  8. '#default_value' => '',
  9. '#size' => 128,
  10. '#maxlength' => 128,
  11. '#required' => FALSE,
  12. '#states' => array(
  13. "visible" => array(
  14. "input[name='check']" => array("checked" => TRUE)),
  15. ),
  16. );

Comments