Posts

Showing posts from April, 2021

Custom Form Error in Symfony 5 (form_errors)

While you can add attributes to form_label and form_widget to customise form_errors you have to use a template. Add a twig template "templates/form/form_errors.html.twig" Paste in the below {% block form_errors %}     {% if errors|length > 0 %}     <ul class="error_list">         {% for error in errors %}             <li>{{ error.message }}</li>         {% endfor %}     </ul>     {% endif %} {% endblock form_errors %} Edit "config/packages/twig.yaml" Add in the template details eg. twig:     default_path: '%kernel.project_dir%/templates'     form_themes:         - 'form/form_errors.html.twig' Based on Symfony 2 instructions found here