Display all errors with form_errors(form) plus for each field in symfony2
error-handling, forms, symfony
Solution
I'm overriding form_div_layout.html.twig in my bundle:
{% block form_errors %}
{% spaceless %}
{% set a = false %}
{% for child in form.children %}
{% if child.get("errors") %}
{% set a = 'true' %}
{% endif %}
{% endfor %}
{% if a == true %}
<div class="alert">
{% for children in form.children %}
{{ form_errors(children) }}
{% endfor %}
</div>
{% endif %}
{% if errors|length > 0 %}
<ul>
{% for error in errors %}
{{
error.messagePluralization is null
? error.messageTemplate|trans(error.messageParameters, 'validators')
: error.messageTemplate|transchoice(error.messagePluralization, error.messageParameters, 'validators')
}}
{% endfor %}
</ul>
{% endif %}
{% endspaceless %}
{% endblock form_errors %}
Now if write `form_errors(form)` it display all error in form and error over each field also indicates.
Problem
I need to display all errors above the form and display a separate error for each field. How can I do this?