Normally, we can have the Symfony Form to output the field errors using the form_errors twig function, but how can we get the specific errors of an individual field, but not display it? Or is there any way that we can examine if one field has errors or not?
通常,我们可以使用Symfony表单使用form_errors twig函数输出字段错误,但是我们如何获取单个字段的特定错误,但不显示它?或者有什么方法可以检查一个字段是否有错误?
2 个解决方案
#1
17
You're looking for form.fieldname.vars.errors
. If you want to check if a form field has errors or not, use the length
filter.
您正在寻找form.fieldname.vars.errors。如果要检查表单字段是否有错误,请使用长度过滤器。
#2
0
You can render error for individual field types. Check Customizing Error Output section of Form rendering cookbook entry.
您可以为各个字段类型呈现错误。检查表单渲染菜谱条目的自定义错误输出部分。
#1
17
You're looking for form.fieldname.vars.errors
. If you want to check if a form field has errors or not, use the length
filter.
您正在寻找form.fieldname.vars.errors。如果要检查表单字段是否有错误,请使用长度过滤器。
#2
0
You can render error for individual field types. Check Customizing Error Output section of Form rendering cookbook entry.
您可以为各个字段类型呈现错误。检查表单渲染菜谱条目的自定义错误输出部分。