Require 2 fields match [RESOLVED]

I would like to know how to require two different fields to match on the same Gravity Form page before allowing a user to click “Next” or “Submit”.

It would be great to know how to accomplish this with two separate fields, as well as with two inputs in the same field.

I found the filter, “gform_is_value_match”, but am unsure of how to use this to accomplish my goal.

I would appreciate any help on this.

Thanks!

I recommend the gform_field_validation filter. Here’s an example showing how to make sure two fields do NOT match. Just flip the logic and use this example to start:

It worked perfectly!

Thanks for your help, Chris!

This is the code I ended up with in case it helps someone in the future.

/* Validate that email fields match */
/* Where 2 is the form id and 216 and 217 are the two fields being compared */
    add_filter( 'gform_field_validation_2_216', function ( $result, $value, $form, $field ) {
        $master = rgpost( 'input_217' );
        if ( $result['is_valid'] && $value !== $master ) {
            $result['is_valid'] = false;
            $result['message']  = 'Please verify that your email is entered correctly in both fields.';
        }
     
        return $result;
    }, 10, 4 );
2 Likes

Thank you for the update!

© 2008 - 2019. Gravity Forms is a project by Rocketgenius Inc.