stoefln
stoefln

Reputation: 14556

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

I have added a second submit button to my form, now Symfony2 complains about it: "This form should not contain extra fields"

Although I added this option in the formtype:

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

Any ideas?

Upvotes: 3

Views: 7472

Answers (1)

kgilden
kgilden

Reputation: 10346

You can most certainly have multiple 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 a name FormType[field_name], you can't have FormType[submit_btn] as the name of the button and you must choose a different one.

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

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

Upvotes: 4

Related Questions