Skip to content

Instantly share code, notes, and snippets.

@phillipwilhelm
Created September 4, 2017 17:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save phillipwilhelm/048191a6411f9093d8f4879d9e991def to your computer and use it in GitHub Desktop.
Save phillipwilhelm/048191a6411f9093d8f4879d9e991def to your computer and use it in GitHub Desktop.
Gravity Forms - API Email Validation for FIELD
// Email validation by third-party API
// The following example shows how you can send the value of an Email type field to a third-party API to determine if the email is valid. In this example we are using the QuickEmailVerification API.
add_filter( 'gform_field_validation', function ( $result, $value, $form, $field ) {
if ( $field->get_input_type() === 'email' && $result['is_valid'] ) {
$request_url = add_query_arg(
array(
'email' => $value,
'apikey' => 'your_api_key_here',
),
'http://api.quickemailverification.com/v1/verify'
);
$response = wp_remote_get( $request_url );
$response_json = wp_remote_retrieve_body( $response );
$response_array = json_decode( $response_json, 1 );
if ( rgar( $response_array, 'result' ) !== 'valid' ) {
$result['is_valid'] = false;
$result['message'] = 'Email is invalid';
}
}
return $result;
}, 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment