Last active
February 6, 2025 11:53
-
-
Save nkb-bd/d15564d0af943d1091a1904edc0f4c85 to your computer and use it in GitHub Desktop.
Email Validation using wp fluent form
This file contains hidden or 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
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've identified a syntax error in the PHP code snippet provided in the issue. The error is on the line:
if (!in_array(form->id, targetFormIds)){
This line is attempting to use the -> operator with a non-object, causing the syntax error. In PHP, the -> operator is used to access properties or methods of an object. However, form appears to be a variable and should be accessed with the $ sign. Furthermore, if form is an associative array, the correct way to access its elements would be using the array syntax.
The corrected line should be:
if (!in_array($form['id'], $targetFormIds)){