Commit 32c96a4c authored by Guillaume Potier's avatar Guillaume Potier

[docs] added cookbook recipe on how to disable CSRF Protection using FormExtension

parent 1d62671c
Disable CSRF Protection on a form using the FormExtension
=========================================================
The *FormExtension* provides a service for building form in your application with the Symfony2 Form component. By default, the *FormExtension* uses the CSRF Protection avoiding Cross-site request forgery, a method by which a malicious user attempts to make your legitimate users unknowingly submit data that they don't intend to submit.
You can find more details about CSRF Protection and CSRF token in the `Symfony2 Book here : <http://symfony.com/doc/current/book/forms.html#csrf-protection>`
In some cases (for example, when embedding a form in an html email) you might want not to use this protection. The easiest way to avoid this is to understand that it is possible to give specific options to your form builder through the `createBuilder()` function.`
Example
-------
::
$form = $app['form.factory']->createBuilder('form', null, array('csrf_protection' => false));
That's it, your form could be submited from everywhere without CSRF Protection.
Going further..
---------------
This specific example showed how to change the `csrf_protection` in the `$options` parameter of the `createBuilder()` function. More of them could be passed through this parameter, it is as simple as using the Symfony2 `getDefaultOptions()` function in your form classes. `See more here <http://symfony.com/doc/current/book/forms.html#book-form-creating-form-classes>`
\ No newline at end of file
...@@ -10,6 +10,7 @@ The cookbook section contains recipes for solving specific problems. ...@@ -10,6 +10,7 @@ The cookbook section contains recipes for solving specific problems.
json_request_body json_request_body
translating_validation_messages translating_validation_messages
session_storage session_storage
form_no_csrf
Recipes Recipes
------- -------
...@@ -21,3 +22,5 @@ Recipes ...@@ -21,3 +22,5 @@ Recipes
* :doc:`Translating Validation Messages<translating_validation_messages>`. * :doc:`Translating Validation Messages<translating_validation_messages>`.
* :doc:`How to use PdoSessionStorage to store sessions in the database <session_storage>`. * :doc:`How to use PdoSessionStorage to store sessions in the database <session_storage>`.
* :doc:`How to disable the CSRF Protection on a form using the FormExtension`.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment