6

I have fieldsets in my form like this

$form['fieldset_1']['name']

and then

$form['fieldset_2']['name']

but when I submit the form and access the values item in $form_state there is only one name value - not as expected ['fieldset_1']['name'] and ['fieldset_2']['name']

can someone help how the form could be submitted and to have access to bot name values ?

2
  • 2
    You should use $form['#tree'] => TRUE in your form if you want submitted data in tree structure. Oct 21, 2013 at 9:01
  • Thanks Jayendra, it helped and now the values are as they should Oct 21, 2013 at 9:14

1 Answer 1

5

You can use the #tree property on both fieldsets, e.g.

$form['fieldset_1'] = array(
  '#type' => 'fieldset',
  '#title' => t('Title 1'),
  '#tree' => TRUE,
);

$form['fieldset_1']['name'] = array(
  '#type' => 'textfield',
  ...
);

$form['fieldset_2'] = array(
  '#type' => 'fieldset',
  '#title' => t('Title 2'),
  '#tree' => TRUE,
);

$form['fieldset_2']['name'] = array(
  '#type' => 'textfield',
  ...
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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