1

How do I globally change the way form validation errors are displayed in Symfony2? For example, if I want to wrap each one of my error messages in a <span class="error"> or something like that, how would that be done?

Note: I'm aware of this question/answer, but I'm not sure that it's the same question as mine, and I don't understand how to apply the selected answer.

Community
  • 1
  • 1
Jason Swett
  • 43,526
  • 67
  • 220
  • 351

2 Answers2

2

Take a look at the docs: custom global theme, customizing error output

1ed
  • 3,668
  • 15
  • 25
0
{# SomeBundle:Layout:fields.html.twig #}
{% block field_errors %}
{% spaceless %}
    {% if errors|length > 0 %}
        <span class="error">
            {% for error in errors %}
                {{ error.messageTemplate|trans(error.messageParameters, 'validators') }}<br />
            {% endfor %}
        </span>
    {% endif %}
{% endspaceless %}
{% endblock field_errors %}

{# In your form template #}
{% form_theme form 'SomeBundle:Layout:fields.html.twig' %}
Cerad
  • 48,157
  • 8
  • 90
  • 92