By Alvin Alexander. Last updated: June 4, 2016
Drupal fieldset FAQ: What is the syntax to make a Drupal fieldset (form fieldset) collapsible?
To make a Drupal form fieldset collapsible, just add the "#collapsible" attribute to your Drupal form definition, like this:
#--------------------------------------
# create a "name" fieldset
#--------------------------------------
$form['name'] = array(
'#type' => 'fieldset',
'#title' => t('Name'),
'#collapsible' => TRUE,
);
$form['name']['firstname'] = array(
'#type' => 'textfield',
'#title' => t('First name'),
);
$form['name']['lastname'] = array(
'#type' => 'textfield',
'#title' => t('Last name'),
);
This example creates a collapsible fieldset named "Name", with two textfields with the labels "First name" and "Last name".
Note that a Drupal fieldset is not collapsible by default, so you need to add this attribute if you do want to make it collapsible.

