Validate unique form

Hi.

This is my form: Sample Page – Waterpolo

I need that the fields “DNI/CI/LE/LC*” and “Confirmar DNI/CI/LE/LC*” have te same entry, otherwise, it has to show this message and not send the form: “Los números de DNI no coinciden”.

I could acomplish this by adding this script in functions.php:

add_filter( 'gform_field_validation_1_2', function ( $result, $value, $form, $field ) {
    $master = rgpost( 'input_53' );
    if ( $result['is_valid'] && $value != $master ) {
        $result['is_valid'] = false;
        $result['message']  = 'Los números de DNI no coinciden.';
    }
  
    return $result;
}, 10, 4 );

The problem es that I can not set the “DNI/CI/LE/LC*” to be unique because it can not repeat the same entry at “Confirmar DNI/CI/LE/LC*” and, then, the confirmation does not work.

My question is how can I change the script so it validates the two fields have te same entry and, also, that is entry is unique.

Thanks a lot for your help!
Jimena

You can use our Custom Field Confirmation snippet to handle this. It will check to make sure the values in your two fields match. If they do not, the form will fail validation and indicate that they do not match.

1 Like