Pipit v0.6

Pipit v0.6 makes it possible to add custom error data when using pipit_form_response(). Note that this is a breaking change so when you upgrade Pipit on an existing project that makes use of pipit_form_response(), you are likely to need to update your JS.

In the previous version, pipit_form_response() returned errors with very little information (just listing the type of error) like this:

{
    "status": 422,
    "errors": { 
        "name": "required",
        "email": "format"
    }
}

In v0.6 the errors are returned as JSON:

{
    "status": 422,
    "errors": { 
        "name": {"type": "required"},
        "email": {"type": "format"}
    }
}

Customising error data

By default the response only includes the error type:

"email": {"type": "format"}    

You can also include additional data to be returned with each error right from your Perch form template using the perch:error conditional tags. Any response-* attribute on the tag is returned with the response:

<perch:error for="email" type="format" response-message="Please enter a valid email address"></perch:error>
"email": {
    "type": "format",
    "message": "Please enter a valid email address"
}

If you follow progressive enhancement principles and the form works without Javascript too, you can still include your server-rendered error message markup inside the perch:error tags:

<perch:error for="email" type="format" response-message="Please enter a valid email address">
    <span class="error">Please enter a valid email address.</span>
</perch:error>
link