I am using gravity forms for a user registration process on a client’s site and it occurred to me they may want to limit who is eligible to submit a registration form on the site. This would cut down on registration spam, make it easier for the administrator to approve new accounts and further secure their members-only area.

To accomplish this I used the gform_field_validation function to have the user type in a passphrase and match it to an already pre-defined phrase we have setup.

Choose a field to use are your passphrase in Gravity Forms and note the field ID. In my example the field ID is : gform_2_9

// Add a passphrase to registartion field in gravity forms
add_filter( 'gform_field_validation_2_9', 'custom_validation', 10, 4 );
function custom_validation( $result, $value, $form, $field ) {
    $arrWhitelist = array('passphrse');  // This can also be multiple commma seprated values for multiple passwords like array('pass1', 'pass2', 'pass3')
    if ( $result['is_valid'] && !in_array( $value, $arrWhitelist )) {
        $result['is_valid'] = false;
        $result['message'] = 'Please enter the correct passphrase to submit this form.';  // Our error message
    }
    return $result;
}

Add the above code to your functions.php file and be sure to change the field ID from _2_9 to whatever your field value is.

Leave a Reply

Get in Touch

Please fill out the form below and we will get back to you ASAP

  • This field is for validation purposes and should be left unchanged.