I am trying to understand how Symfony works, so I tried to create two forms on the same page: one form for the firstname and the other for the email (I want two different forms so two different submit buttons).
I have the error This form should not contain extra fields.
with Symfony 4 after I submit the form. The invalid value is the email.The violation message says "{{ extra_fields }}" => ""email"
"
I read in the Symfony documentation that I have to enable the option allow_extra_fields
.
So this is what I tried :
$emailForm = $this->createFormBuilder(['allow_extra_fields' => true])
->add('email' )
->add('Submit',SubmitType::class)
->getForm();
but it didn't work. How can I remove the error message ? There are a few previous posts about the error but the version 4 of Symfony seems to work differently.
This is a bit more of code :
$userForm = $this->createFormBuilder($defaultData)
->add('firstname', TextType::class)
->add('email', EmailType::class)
->add('description', TextType::class)
->add('Submit', SubmitType::class)
->getForm();
$userForm->handleRequest($request);
$defaultData = ['pass' => '', 'conf_pass' => ''];
$passForm = $this->createFormBuilder($defaultData)
->add('pass', PasswordType::class, ['label' => 'Change password'])
->add('conf_pass', PasswordType::class, ['label' => 'Confirm password'])
->add('Submit', SubmitType::class)
->getForm();
$passForm->handleRequest($request);
I think the problem comes from the fact that I am handling two times, but I'm not sure at all ...