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.

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

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' %}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.