I'd like to tidy up an unwieldy node edit form using collapsible fieldset elements.

I can do this by implementing a form_alter hook but will this affect Drupal/other modules' ability to process/validate the fields? Obviously it will change the #parents of several elements, and I'm unclear whether this change will also affect $form_state['values'].

Is it safe to do this, or is there another way to achieve the same?

Example code

$form['group1'] = [
  '#type' => 'fieldset',
  '#title' => 'My Grouped Fields',
  '#collapsible' => TRUE,
  '#collapsed' => TRUE,
  'children' => [
    'body' => $form['body'],
    'field_smallprint' => $form['field_smallprint']
unset($form['body'], $form['field_smallprint']);

It seems to me that this is probably safe unless #tree is TRUE, but I don't want to implement something that might lose data, hence the question here.


I would recommend you to first try the Field Group module that provides the option to do that kind of grouping and many more options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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