I need to display all errors above the form and display a separate error for each field. How can I do this?
In Symfony 3.2, to get all form errors in a template, you can use a bit hacky, but simple and working solution using form.vars.errors.form.getErrors(true)
:
<ul>
{% for error in formView.vars.errors.form.getErrors(true) %}
<li>{{ error.message }}</li>
{% endfor %}
</ul>
The trick is that:
formView.vars.errors.form
),form.getErrors(true)
gives you a recursive iterator over all form errors.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With