Pipit: pipit_form_set_error_vars()

Add a variable to the template engine for each form field that has any error

pipit_form_set_error_vars();

The variables take the following format:

{formID}_error_{fieldID}

This allows you to use a single perch:if tag to check if a form field returned an error after a failed form submission:

<perch:form id="register" method="post" app="perch_members">
    <perch:label for="email">Email</perch:label>
    <perch:input id="email" type="email" required helper="PerchMembers_Members::check_email" />

    <perch:if exists="register_error_email">
        <!--* the input field with the ID email returned an error *-->
    </perch:if>
</perch:form>

While Perch comes with perch:error conditional tags, each tag pair can only be used to check for a single error type:

<perch:label for="email">Email</perch:label>
<perch:input id="email" type="email" required helper="PerchMembers_Members::check_email" />

<perch:error for="email" type="required">
    <p>Please add your email address</p>
</perch:error>

<perch:error for="email" type="helper">
    <p>That email address is already in use</p>
</perch:error>

This makes it harder to check if a given field has at least one error, which is something you may want to do to conditionally add a class to highlight the field(s) that returned an error.

<div class="field has-error">
    <perch:label for="email">Email</perch:label>
    <perch:input id="email" type="email" required helper="PerchMembers_Members::check_email" />
</div>

If you use pipit_form_set_error_vars(), you will be able to:

<div class="field <perch:if exists="contact_error_email">has-error</perch:if">
    <perch:label for="email">Email</perch:label>
    <perch:input id="email" type="email" required helper="PerchMembers_Members::check_email" />

    <perch:error for="email" type="required">
        <p>Please add your email address</p>
    </perch:error>

    <perch:error for="email" type="helper">
        <p>That email address is already in use</p>
    </perch:error>
</div>
link