Skip to content

Commit

Permalink
Added truemail verification
Browse files Browse the repository at this point in the history
  • Loading branch information
techjewel committed May 4, 2020
1 parent 3bd05c1 commit 56cd1d7
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Please use which are appropriate for you.

- `Email Validation` Limit Email Domains (Accept only particular Domains) [View Snippet](https://github.com/WPManageNinja/fluentform-snippets/wiki/Limit-Email-Domains)
- `Email Validation` Ban Email Domains (Ban particular Domains) [View Snippet](https://github.com/WPManageNinja/fluentform-snippets/wiki/Ban-Email-Domains)
- `Email Validation with TrueMail` Validate Email with TrueMail API [View Snippet](https://github.com/WPManageNinja/fluentform-snippets/blob/master/php-snippets/email-varification-with-truemail.php)
- `TextArea Validation` Check if textarea contain url. if yes, make the form submission failed. [View Snippet](https://github.com/WPManageNinja/fluentform-snippets/blob/master/php-snippets/custom-validation-example.php)


Expand Down
85 changes: 85 additions & 0 deletions php-snippets/email-varification-with-truemail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

/*
* This snippet will for your email fields where You can verify the provided email
* using truemail api
*/

/*
* Snippet: 1
* This will apply for all the forms in your site
*/

add_filter('fluentform_validate_input_item_input_email', function ($default, $field, $formData, $fields, $form) {

$errorMessage = 'Looks like email is not correct'; // You may change here
$trueMailApiKey = 'INSERT_YOUR_TRUEMAIL.IO_API_KEY';

$fieldName = $field['name'];
if (empty($formData[$fieldName])) {
return $default;
}
$email = $formData[$fieldName];


$request = wp_remote_get('https://truemail.io/api/v1/verify/single?address_info=1&timeout=5&access_token='.$trueMailApiKey.'&email='.$email);

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['result'] == 'valid') {
return $default;
}

return $errorMessage;

}, 10, 5);




/*
* Snippet: 2
* This will apply for only form id: 12
*/
add_filter('fluentform_validate_input_item_input_email', function ($default, $field, $formData, $fields, $form) {

// You may change the following 3 lines
$targetFormId = 12;
$errorMessage = 'Looks like email is not correct'; // You may change here
$trueMailApiKey = 'INSERT_YOUR_TRUEMAIL.IO_API_KEY';

if ($form->id != $targetFormId) {
return $default;
}

$fieldName = $field['name'];
if (empty($formData[$fieldName])) {
return $default;
}
$email = $formData[$fieldName];


$request = wp_remote_get('https://truemail.io/api/v1/verify/single?address_info=1&timeout=5&access_token='.$trueMailApiKey.'&email='.$email);

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['result'] == 'valid') {
return $default;
}

return $errorMessage;

}, 10, 5);

0 comments on commit 56cd1d7

Please sign in to comment.