symfony2 CSRF invalid symfony2 CSRF invalid symfony symfony

symfony2 CSRF invalid


Are you by chance using $form->bindRequest() in the action which produces the CSRF error? I had this issue. You should not be binding the request for a new form. If you are posting the form to the same action, wrap the bindRequest in a conditional which checks if method is POST:

if ($this->getRequest()->getMethod() == 'POST') {  $form->bindRequest($this->getRequest());  if ($form->isValid()) {    ...  }}


There is no problem using {{ form_widget(form) }} to build your custom form.All you have to do is add the _token like this:{{ form_widget(form._token) }}


This error had me crazy for days!Thanks krishna!If in your form template you choose to not use the default form behavior {{ form_widget(form) }} you SHOULD put {{ form_rest(form) }}Hope this could help anyone else!