Skip to content

Instantly share code, notes, and snippets.

@nkb-bd
Last active February 6, 2025 11:53
Show Gist options
  • Save nkb-bd/d15564d0af943d1091a1904edc0f4c85 to your computer and use it in GitHub Desktop.
Save nkb-bd/d15564d0af943d1091a1904edc0f4c85 to your computer and use it in GitHub Desktop.
Email Validation using wp fluent form
add_filter('fluentform/validate_input_item_input_email', function ($default, $field, $formData, $fields, $form) {
// You may change the following 3 lines
$targetFormIds = [140,141];
$errorMessage = 'Looks like email is not correct'; // You may change here
$emailableApiKey = 'live_b67c9cb0585e27dd256c';
if (!in_array($form->id, $targetFormIds)){
return $default;
}
$fieldName = $field['name'];
if (empty($formData[$fieldName])) {
return $default;
}
$email = $formData[$fieldName];
$request = wp_remote_get('https://api.emailable.com/v1/verify?email='.$email.'&api_key='.$emailableApiKey);
if(is_wp_error($request)) {
return $default; // request failed so we are skipping validation
}
$response = wp_remote_retrieve_body($request);
$response = json_decode($response, true);
if($response['state'] == 'deliverable') {
return $default;
}
return $errorMessage;
}, 10, 5);
@nkb-bd
Copy link
Author

nkb-bd commented Jan 9, 2024

Thanks I have updated it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment