#[1]gnikyt feed
[2]gnikyt Code ramblings.
Get single field error in Symfony
/* Dec 12, 2013 — 927B */
This is just a quick tid-bit/how-to!
Recently a project came up where special front-end actions and
structures had to take place within the view of the Twig template once
an error occurred on specific fields. It also didn’t require enough
attention to warrant creating a form theme.
This is a quick way to test if a field has errors; Simply do this
inside your Twig template…
{% raw %}{{ form.__field_name__.vars.errors|length }}{% endraw %}
The above code will show how many errors a certain field has. A usage
example…
{% raw %}
{% if form.__field_name__.vars.errors|length > 0 %}
{{ form_errors(__field_name__) }}
{% endif %}
{% endraw %}
Just replace field_name with the field name you wish to use!
[3]MD | [4]TXT | [5]CC-4.0
This post is 11 years old and may contain outdated information.
__________________________________________________________________
[6]Ty King
Ty King
A self-taught, seasoned, and versatile developer from Newfoundland.
Crafting innovative solutions with care and expertise. See more
[7]about me.
[8]Github [9]LinkedIn [10]CV [11]RSS
*
*
*
*
*
*
*
*
*
*
References
1. /rss.xml
2. /
3. /get-single-field-error-in-symfony/index.md
4. /get-single-field-error-in-symfony/index.txt
5. https://creativecommons.org/licenses/by/4.0/
6. /about
7. /about
8. https://github.com/gnikyt
9. https://linkedin.com/in/gnikyt
10. /assets/files/cv.pdf
11. /rss.xml