Open JevgenijVisockij opened 3 years ago
If a page contains multiple forms, each form submission can be detected and processed individually:
public function myAction(Request $request): Response
{
$form1 = $this
->createForm(/*...*/)
->handleRequest($request)
;
if ($form1->isSubmitted() && $form1->isValid()) {
// ...
}
$form2 = $this
->createForm(/*...*/)
->handleRequest($request)
;
if ($form2->isSubmitted() && $form2->isValid()) {
// ...
}
return $this->render('...', [
'form1' => $form1->createView(),
'form2' => $form2->createView(),
]);
}
If I am not wrong, we could use the same POST route to process a form and a list:
admin_emails_save_options: /configure/advanced/emails/options[POST]
If we use the FormInterface::isSubmitted()
method to detect form submission, we could process this use case alongside the list. Testing FormInterface::isValid()
alone won't work in this particular case.
FormInterface::isSubmitted()
is supposed to recognize the form name in POST data.
@JevgenijVisockij you make a serious point about form usage.
In my humble opinion: