Symfony2: get rid of "This form should not contain additional fields"

I added a second form to submit to my form, now Symfony2 complains about this: "This form should not contain additional fields"

Although I added this option to formtype:

public function getDefaultOptions(array $options) { return array( 'csrf_protection' => false, ); } 

Any ideas?

+3
forms symfony
source share
1 answer

You probably have a few submit buttons. Make sure the button is not in the same array as the other form fields.

So, for example, if your form fields have the name FormType[field_name] , you cannot have FormType[submit_btn] as the name of the button, and you must choose another.

Your controller may act differently depending on the button pressed. If your submit buttons are named submit_1 and submit_2 , you may have something similar to

 if($this->getRequest()->request->has('submit_1')) { // do stuff } else { // do other stuff } 
+4
source share

All Articles