I'm using amforms and would like to display all form errors at the top of my page, not just per field. I can't seem to find the answer in the docs. Is this option available?

  • Never used the plugin, but looking at the docs, I'd suspect formHandle.getErrors() would return a multi-dimensional array with the key being the attribute and the values being an array of errors.
    – Brad Bell
    Sep 4 '17 at 1:26

I'm not sure if this is the intended way, but I rigged this up and so far it works well.

{% set yankee = craft.amForms.getForm('hotel') %}

{% macro foxtrot(errors) %}
    {% if errors %}
        <ul class="errors">
            {% for error in errors %}
                <li>{{ error }}</li>
            {% endfor %}
    {% endif %}
{% endmacro %}

{% from _self import foxtrot %}

{# list of form errors #}
{% if hotel is defined %}
    <div class="error-class">
        {% set fields = yankee.getFields() %}
        <h4>Please correct the errors listed below before submitting the form.</h4>
            {% for field in fields %}
                {{ foxtrot(hotel.getErrors(field.handle)) }}
            {% endfor %}
{% endif %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.