I'm stuck with the following problem. I have 3 forms on one page (might be more in the future). when I submit them.. nothing happens (inserting data in the DB) and the other 2 forms get their fields filled in. Might be because they all have a 'name' field? How can I solve this.. so that each forms has is own 'function' and it doesn't interfere with the other forms.
My twig:
<div class="box">
<h2>Form1</h2>
{{ form_start(form1) }}
{{ form_widget(form1) }}
{{ form_end(form1) }}
</div>
<div class="box">
<h2>Form2</h2>
{{ form_start(form2) }}
{{ form_widget(form2) }}
{{ form_end(form2) }}
</div>
<div class="box">
<h2>Form3</h2>
{{ form_start(form3) }}
{{ form_widget(form3) }}
{{ form_end(form3) }}
</div>
My controller:
if ($request->isMethod('POST')) {
$form1->handleRequest($request);
$form2->handleRequest($request);
$form3->handleRequest($request);
if ($form1->isSubmitted() && $form1->isValid() && $request->request->has('form1')) {
// Do data insert
//Return to page
} else if ($form2->isSubmitted() && $form2->isValid() && $request->request->has('form2')) {
// Do data insert
//Return to page
} else if ($form3->isSubmitted() && $form3->isValid() && $request->request->has('form2')) {
// Do data insert
//Return to page
}
}
$request->request->has('form1')since you already have$form1->isSubmitted(). Also check that the submitted forms are valid, they might just not be validating.$request->request->has('form1'did indeed help with values gettin in the other forms. form1 gets submitted perfectly, but when I try to submit the other 2.. they seems to point to the first form. They try to insert their data in that query - which is ofcourse not ok.