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.

  1. Add a twig template "templates/form/form_errors.html.twig"
  2. 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 %}
  3. Edit "config/packages/twig.yaml"
  4. 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

Comments

Popular posts from this blog

qshape command not found - Postfix

Using variables within ajax success function that were set before ajax call (JQuery)