问题描述
我正在使用 Symfony2.1 。
它具有针对表单的内置 CSRF保护。 CSRF令牌无效时返回的错误消息是: CSRF令牌无效。请尝试重新提交表单。
I使用经典调用将其显示在Twig模板的表单顶部:
{{form_errors(form)}}
如何更改返回的消息?
有任何想法吗?
您尝试在文件 validators中设置吗?{locale_code } .yml
为密钥设置转换CSRF令牌无效。请尝试重新提交表格
吗?
要更改默认消息,您可以尝试以下方法:
#MyBundle\资源\翻译\验证器.en.yml
CSRF令牌无效。请尝试重新提交以下表单:我的自定义CSRF错误
抛出错误消息,它属于FormError类,因此应该是可以翻译。
I'm using Symfony2.1.It has a builtin CSRF protection for the forms. The error message returned when the CSRF token is invalid is: "The CSRF token is invalid. Please try to resubmit the form".
I show it on the top of the form in my Twig template by using the classic call:
{{ form_errors(form) }}
How can I change the returned message?
In alternative, a more advanced possibility is to catch this error type in order to show a lot of options/links in my Twig template.Any idea?
Did you try to set in the file validators.{locale_code}.yml
to set a translation for key The CSRF token is invalid. Please try to resubmit the form
?To change the default message you can try this out:
#MyBundle\Resources\translations\validators.en.yml
The CSRF token is invalid. Please try to resubmit the form : My custom CSRF error
The error message is thrown here and it is of FormError class...thus it should be possible to translate it.
这篇关于在Symfony2.1中手动更改或捕获无效CSRF令牌的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!