Monday, March 21, 2016

Symfony 2 How To Disable CSRF on a Per Form Basis

Here are two ways to disable the CSRF in Symfony 2 Forms:
public function getDefaultOptions(array $options)
   {
       return array(
           'data_class'      => 'Acme\TaskBundle\Entity\Task',
           'csrf_protection' => false,  // <---- set this to false on a per Form Type basis
           //'csrf_field_name' => '_token',
           // a unique key to help generate the secret token
           //'intention'       => 'task_item',
       );
   }
And while creating the form:
$form = $this->createFormBuilder($users, array(
    'csrf_protection' => false,  // <---- set this to false on a per Form Instance basis
))->add(...)
;
If this has been helpful please donate, thanks!
http://www.craftitonline.com/2011/08/symfony-2-how-to-disable-csrf-on-a-per-form-basis/

No comments:

Post a Comment