Created
September 4, 2017 17:57
-
-
Save phillipwilhelm/048191a6411f9093d8f4879d9e991def to your computer and use it in GitHub Desktop.
Gravity Forms - API Email Validation for FIELD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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