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.