By Alvin Alexander. Last updated: June 4, 2016
Drupal fieldset FAQ: How do I make a Drupal fieldset initially collapsed?
To make a Drupal fieldset collapsed initially, make the fieldset collapsible, then set the "collapsed" property TRUE, like this:
#-------------------------------------- # create a "name" fieldset #-------------------------------------- $form['name'] = array( '#type' => 'fieldset', '#title' => t('Name'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['name']['firstname'] = array( '#type' => 'textfield', '#title' => t('First name'), ); $form['name']['lastname'] = array( '#type' => 'textfield', '#title' => t('Last name'), );
The Drupal form collapsible attribute makes the fieldset collapsible (it's not collapsible by default), and the collapsed property makes the fieldset collapsed by default when your Drupal form is first display.