2

I am having some issues understanding why validation is not working on my entry forms.

I've got an entry with several field types which aren't of type "entries" and the required validation is working properly on my front end forms using craft's error macro

{% macro errorList(errors) %}
    {% if errors %}
        {% for error in errors %}
        {% endfor %}
    {% endif %}
{% endmacro %}

The validation is NOT working on my fields which are of type "entries". Do you have to pass in the error object differently to the macro since "entries" are an array?

I have tried calling the error macro like this...

{% if entry is defined %}
    {{ formErrors.errorList(entry.getErrors('houseCollege[0]')) }}
{% endif %}

and this...

{% if entry is defined %}
    {{ formErrors.errorList(entry.getErrors('houseCollege[]')) }}
{% endif %}

and this...

{% if entry is defined %}
    {{ formErrors.errorList(entry.getErrors('houseCollege')) }}
{% endif %}

and yes, I have this field marked as required in the CP.

Also I don't know how relevant this is, but in the form this value is being filled by a select element.

1

Relational field validation (entries, assets, tags, users, etc.) works the same on the front-end as any other custom field would.

So if you have an Entries field with a handle houseCollege on an entry and it's marked as required and there is nothing submitted on the front-end for it, then using the error macro you mentioned:

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

You would display any validation errors for that houseCollege field with:

{% if entry is defined %}
    {{ errorList(entry.getErrors('houseCollege')) }}
{% endif %}

And in the case of a missing required field, you'd get:

House College cannot be blank.
|improve this answer|||||

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.