How can I debug why in all my browsers I got The CSRF token is invalid error, but when I test same form with Functional test it works?
Asked
Active
Viewed 3,943 times
4 Answers
2
If you customized the way form renders the inputs check if you added {{form_rest(form) }} like in the next example.
Example
<form action="{{ path('BloggerBlogBundle_contact') }}" method="post" {{ form_enctype(form) }}>
{{ form_errors(form) }}
{{ form_row(form.name) }}
{{ form_row(form.email) }}
{{ form_row(form.subject) }}
{{ form_row(form.body) }}
{{ form_rest(form) }}
<input type="submit" value="Submit" />
</form>

Robert
- 1,117
- 8
- 10
-
1i got only {{ form_widget(form) }} in template. token is visible in html source – Paweł Madej May 19 '12 at 20:23
2
When I commented my config.yml as below, everything started working? so new question is: What is wrong with commented part of this configuration?
session:
auto_start: true
# cookie_lifetime: 86400
# cookie_path: \
# cookie_domain: example.com
# cookie_secure: true
# cookie_httponly: true

Paweł Madej
- 1,229
- 23
- 42
2
For me disabling secure cookie resolved this problem after upgrading from symfony 2.0.16 to 2.1.6:
session:
cookie_lifetime: 3600
cookie_path: \
cookie_domain: .%base_domain%
cookie_secure: false
cookie_httponly: true

user2007216
- 21
- 1
-5
You can Use @csrf_exempt decorator to excempt csrf token for this you have to import
from django.views.decorators.csrf import csrf_exempt
then write @csrf_exempt before your view
this will work properly :)

Neeraj Sharma
- 1,322
- 10
- 9