I have been using the symfony form structure for a while. But I would like to know if anyone has a better approach to implementing forms dynamically.
The problem arises when I insert the form (see below), I need to specify the index of the array, as Fabian explains how the sfForm object looks like a multidimensional array in this article Advanced forms .
If I want to give the user the opportunity to click the button and paste another form, how can I achieve the following if they click the button several times:
<input type="parent[child][]" />
<input type="parent[child][]" />
<input type="parent[child][]" />
... repeated how many times the user clicks the button. I can use fast javascript to copy and paste form elements in the DOM.
Instead of this:
<input type="parent[child][1]" />
<input type="parent[child][2]" />
<input type="parent[child][3]" />
... , . javascript, , , . , Ajax PHP, . , .
:
$parentForm = new ParentForm($parent)
$child = new child();
$child->setParent($parent);
$sfForm = new sfForm();
$sfForm ->embedForm($someIndex, new ChildForm($child));
$parentForm->embedForm('child', $sfForm);