version 0.24


    package MyApp::Form::Foo;
    use HTML::FormHandler::Moose;

    with 'HTML::FormHandlerX::JQueryRemoteValidator';


    # You need to provide a form validation script at /ajax/formvalidator
    # In Poet/Mason, something like this in /ajax/ -

    route ':form_name/:field_name';

    method handle () {
        my $form = $.form($.form_name);
        $form->process(params => $.args, no_update => 1);

        my $err = join ' ', @{$form->field($.field_name)->errors};
        my $result = $err || 'true';



The purpose of this package is to build a set of JQuery scripts and inject them into your forms. The scripts send user input to your server where you must provide an endpoint that can validate the fields. Since you already have an HTML::FormHandler form, you can use that.

The package uses the remote validation feature of the JQuery Validator framework. This also takes care of updating your form to notify the user of errors and successes while they fill in the form. You will most likely want to customise that behaviour for your own situation. An example is given below.

What you will need


Load the JQuery library somewhere on your page.

JQuery validator

See the jquery_validator_link attribute.

Server-side validation endpoint

See the validation_endpoint attribute.

Some JS fragments to update the form
CSS to prettify it all

An example using the Bootstrap 3 framework


    <form ...>

    <div class="form-group form-group-sm">
        <label class="col-xs-3 control-label" for=""></label>
        <div class="col-xs-6">
            <input type="text" name="" id=""
                class="form-control" value="" />
        <label for="" id=""
            class="has-error control-label col-xs-3">

    <div class="form-group form-group-sm">
        <label class="col-xs-3 control-label" for="AddressForm.address"></label>
        <div class="col-xs-6">
            <input type="text" name="AddressForm.address" id="AddressForm.address"
                class="form-control" value="" />
        <label for="AddressForm.address" id="AddressForm.address-error"
            class="has-error control-label col-xs-3">




Most of the classes on the form come from Twitter Bootstrap 3. In this example, JQuery validator targets error messages to the second <label> on each form-control. This is the default behaviour but can be changed.

The default setup will display and remove messages as the user progresses through the form. JQuery Validator offers lots of options. You can read about them at You should start by reading the few sentences at the very bottom of that page.

Some useful additional styling to get started:

    label.valid {
      width: 24px;
      height: 24px;
      background: url(/static/images/valid.png) center center no-repeat;
      display: inline-block;
      text-indent: -9999px;

    label.error {
      font-weight: normal;
      color: red;
      padding: 2px 8px;
      margin-top: 2px;


You can provide extra JavaScript functions to control the behaviour of the error and success messages in the jqr_validate_options attribute:

    my $jqr_validate_options = {
        highlight => q/function(element, errorClass, validClass) {
        unhighlight => q/function(element, errorClass, validClass) {
        success => q/function(errorLabel, element) {
        errorClass => '"has-error"',
        validClass => '"has-success"',
        errorPlacement => q/function(errorLabel, element) {
                errorLabel.appendTo( element.parent("div").parent("div") );

    has '+jqr_validate_options' => (default => sub {$jqr_validate_options});

Class (form) attributes


Default: /ajax/formvalidator

The form data will be POSTed to [validation_endpoint]/[form_name]/[field_name].

Note that *all* fields are submitted, not just the field being validated.

You must write the code to handle this submission. The response should be a JSON string, either true if the field passed its tests, or a message describing the error. The message will be displayed on the form.

The synopsis has an example for Poet/Mason.


You can leave this as-is, or if you prefer, you can put the file on your own server and modify this setting to point to it.


Default: {}

A HashRef, keys being the keys of the validate JQuery validator call documented at, with values being JavaScript functions etc. as described there.


Default: [ qw(Submit Hidden noCAPTCHA Display JSON JavaScript) ]

A list of field types that should not be included in the validation calls.


Boolean, default 0.

A flag to turn off remote validation altogether, perhaps useful during form development.

Field attributes

Tag no_remote_validate [Bool]

Default: not set

Set this tag to a true value on fields that should not be remotely validated:

    has_field 'foo' => (tags => {no_remote_validate => 1}, ... );

See also


This started out as a modification of Aaron Trevana's HTML::FormHandlerX::Form::JQueryValidator


Dave Baird <>


This software is copyright (c) 2016 by David R. Baird.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.