I am working with Symfony 6 forms. I tried submitting the form using the submit()
method. From the documentation Symfony Form Direct Submit the cause of the error is spelled out as "The list of fields submitted with the submit() method must be the same as the fields defined by the form class. Otherwise, you'll see a form validation error:". How do I debug and in fact, solve this kind of error?
You can get the errors of the form with $form->getErrors()
.
Using the following $form->submit($request->request->get($form->getName()));
should fail with the recent changes of the component. Returning an array from the get method fails with the non-scalar error message.
Instead, you have to use either this
$allValues = $request->request->all();
$form->submit($allValues[$form->getName()]);
or this, more condensed,
$form->submit($request->request->all()[$form->getName()]);