symfony2 CSRF invalid

前端 未结 3 499
深忆病人
深忆病人 2020-12-08 08:14

Okay, so today I updated my database with new information from our \'live\' database... And since then I\'ve been having issues on one of my forms. If you need any code le

相关标签:
3条回答
  • 2020-12-08 08:20

    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!

    0 讨论(0)
  • 2020-12-08 08:21

    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) }}

    0 讨论(0)
  • 2020-12-08 08:23

    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()) {
        ...
      }
    }
    
    0 讨论(0)
提交回复
热议问题