Symfony 2 This form should not contain extra fields Symfony 2 This form should not contain extra fields symfony symfony

Symfony 2 This form should not contain extra fields


It seems to me that you have the problem because of the token field. If it is so, try to add options to createFormBuilder():

$this->createFormBuilder($search, array(        'csrf_protection' => true,        'csrf_field_name' => '_token',    ))    ->add('searchinput', 'text', array('label'=>false, 'required' =>false))    ->add('search', 'submit')    ->getForm();

To find out the extra field use this code in controller, where you get the request:

$data = $request->request->all();print("REQUEST DATA<br/>");foreach ($data as $k => $d) {    print("$k: <pre>"); print_r($d); print("</pre>");}$children = $form->all();print("<br/>FORM CHILDREN<br/>");foreach ($children as $ch) {    print($ch->getName() . "<br/>");}$data = array_diff_key($data, $children);//$data contains now extra fieldsprint("<br/>DIFF DATA<br/>");foreach ($data as $k => $d) {    print("$k: <pre>"); print_r($d); print("</pre>");}$form->bind($data);


This message is also possible if you added/changed fields in your createFormBuilder() and press refresh in your browser...

In this case it's ok after sending the form again ;-)


I got the same message while having multiple forms on the same page. Turns out, symfony defaults to the name 'form' for all of them. Instead of using createFormBuilder, you can change the name of the form to avoid conflicts using

public FormBuilderInterface createNamedBuilder(string $name, string|FormTypeInterface $type = 'form', mixed $data = null, array $options = array(), FormBuilderInterface $parent = null)

See https://stackoverflow.com/a/13366086/1025437 for an example.