The Symfony 2.3 docs say that it is possible to customize global form errors (errors that appear at top of form that are not tied to a specific field).
http://symfony.com/doc/current/cookbook/form/form_customization.html#customizing-error-output
"You can also customize the error output for just one specific field type. For example, certain errors that are more global to your form (i.e. not specific to just one field) are rendered separately, usually at the top of your form..."
They go on to say that:
"To customize only the markup used for these errors, follow the same directions as above, but now call the block form_errors"
I am confused as to what they are talking about. It seems that their prior instructions already call the block "form_errors" so I am not sure what is different.
How do I customize just the global form errors (the individual form field errors should remain the same)?
The wording on that page is confusing. I had to read it a few times too, and it feels like there should be more information. The example provided shows how to check if the error is a "compound" error (for the whole form) or just an error for the individual field.
This is how my block looks:
{% block form_errors %}
{% if errors|length > 0 %}
<ul class="alert alert-warning {% if compound %}formError{% else %}formInputError{% endif %}">
{% for error in errors %}
<li>{{ error.message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endblock form_errors %}
If it's a compound form, it renders the class as formError
, and if it's just for an input it renders formInputError
. That let's me style them slightly different, depending on if they appear at the top of the page or above an input. You could also make them completely separate HTML if you needed.