Most people have filled out a long form, clicked Submit, and been sent back to the top: the username is taken, the code is invalid, a date is in the wrong range. The form knew the rules all along. It just didn’t check them until the end.
Many “live validation” tools only check the shape of a value in the browser: is this an email address, is this field empty. They can’t check whether that email is already registered, or whether a member ID exists, because those rules live on your server.
GravityOps Live Field Validation closes that gap for Gravity Forms.
The same rules as Submit, one field at a time
When someone leaves a field (or changes a dropdown, checkbox or radio button), Live Field Validation sends that field to your server and runs Gravity Forms’ own validation on it, the same check a real submission runs:
- required fields and field formats
- No Duplicates, so “this email is already registered” shows up right away
- your custom validation rules (
gform_field_validation)
If the value fails, the error appears under the field, styled like a normal Gravity Forms error. The whole form’s current values are sent along, so a rule that compares two fields, such as an end date that must come after the start date, still works.
Even on a form with no custom rules, that is a better experience: people fix each mistake while they are still on that field, not after they submit. The more custom validation a form has, the more it helps.
Because it is your server’s own check, what people see while filling the form is exactly what Submit will enforce. There is no second copy of your rules to keep in sync.
Your custom rules, now live
If you already validate with gform_field_validation, there is nothing new to write. A rule like this one, which refuses usernames that are taken:
add_filter( 'gform_field_validation_12_3', function ( $result, $value ) {
if ( $result['is_valid'] && username_exists( $value ) ) {
$result['is_valid'] = false;
$result['message'] = 'That username is taken. Please choose another.';
}
return $result;
}, 10, 2 );
…now runs the moment the user leaves the username field instead of after Submit. The same goes for a promo code checked against a list, a member ID that must exist, or a value that has to match an earlier entry.
One limit to know: validation runs per field. Rules that need the whole submission at once (the form-wide gform_validation filter) still run on Submit, which is the only point where the whole form is filled in.
Acting on the result
After each field is checked, Live Field Validation fires a JavaScript event with the form ID, the field ID and whether it passed:
jQuery( document ).on( 'gravityops_lgfv_field_validated', function ( event, formId, fieldId, isValid ) {
// React to a field becoming valid or invalid.
} );
That lets a form react to validation, not just display it. We built it for a payment form where the card was charged before the form was submitted, with no way to stop the payment afterwards. We kept the payment field hidden until every field before it had passed server-side validation, so no one could pay on a submission that was going to fail.
The details
- You choose where it runs. Turn it on per form and pick the fields on the form’s Live Validation settings tab. Optional fields can be included too.
- A Forms console lists every form with eligible fields, shows how many are covered, and turns live validation on or off with one click.
- A Tester tab runs a field’s validation against a value you type, without filling out the form. It is the quickest way to check a custom rule.
- Pre-filled fields are checked on load. Values set by defaults or by Gravity Perks Populate Anything are validated as soon as the page opens, and again when Populate Anything updates them.
- Multi-page forms keep their state between pages, including after a reload or the browser’s back button.
- Hidden fields are skipped. When conditional logic hides a field, its pending check and its error go away.
Try it
If your forms have rules, Live Field Validation lets people meet them while they fill the form in, not after they submit it.
Get GravityOps Live Field Validation
Discuss this post
Questions, corrections or your own approach? Reply in the community thread.