Question

How do I give a subform a name so it will send it's data in the respective post key? In The following example the name for the main form is "form" and the name of both subforms is also "form", which results in only one subform beeing displayed. the post data looks like this:

form[form][amount]=
form[form][value]=

In this sample code $mainForm, $subForm1 and $subForm2 are instances of FormBuilder.

$subForm1->add('amount', 'text');
$subForm1->add('value', 'text');
$mainForm->add($subForm1);

$subForm2->add('amount', 'text');
$subForm2->add('value', 'text');
$mainForm->add($subForm2);

So How can I change it send the post data like following?

form[subForm1][amount]=
form[subForm1][value]=
form[subForm2][amount]=
form[subForm2][value]=
Was it helpful?

Solution

How are you creating your FormBuilders?

If you're using the FormFactory, you can use the createNamed() or createNamedBuilder() methods on the factory to set a name.

Alternatively, you can call $mainForm->create($name) to create a named form (note that all that does is call $mainForm's Factory and does not automatically add it to $mainForm.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top