Where/how to implement gform_field_validation

I’m trying to implement a validation across two fields where a user is required to enter their Parent/Guardian’s email address as well as their own.

The purpose of validation is to ensure the same email address is not entered in both fields.

I have narrowed down what seems to be what I need … but I can’t work out where and how to implement/call it. It has been added to the functions.php file within the Child theme (or does it need to go in the main theme?)

add_filter( 'gform_field_validation_1_5' , function ( $result , $value , $form , $field ) {
$master = rgpost( 'input_21' );
if ( $result [ 'is_valid' ] && $value == $master ) {
$result [ 'is_valid' ] = false;
$result [ 'message' ] = 'Please enter a different email.' ;
return $result ;
}, 10, 4 );

Never mind … as I’ve just worked out — this runs when the form is submitted.
Is there a way to have the validation run as data is being entered, or is that bad practice?

Thanks in advance.

Hi Paul. The gform_field_validation filter runs after the form or page is submitted. There is currently no live validation in Gravity Forms. We have an open feature request for that, but it’s not currently a feature of the plugin.

There is a third party plugin which might be able to do this for you. I’ve never used it but it might be worth a look:

Thanks Chris. No real drama on the live validation — our needs on this project are met (and surpassed) with Gravity Forms as is.

Thanks :slight_smile:

1 Like