Last active
February 6, 2023 14:09
-
-
Save gmmedia/e005cb1139c7e049d094b6741c36cfb3 to your computer and use it in GitHub Desktop.
FluentForms - Email Blacklist - Specific Forms
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
<?php | |
// FluentForms - Email Blacklist - Specific Forms | |
// Need help: https://bloggerpilot.com/snippet-fluentforms-e-mail-blacklist/ | |
add_filter('fluentform_validate_input_item_input_email', function ($error, $field, $formData, $fields, $form) { | |
The ID(s) of the form | |
$targetFormId = [13,14]; | |
// These listed domains will fail to submit the form | |
$blacklistDomains = ['gmail.com', 'hotmail.com', 'test.com']; | |
// You can edit your error message here | |
$errorMessage = 'The provided email domain is not accepted'; | |
if (!in_array($form->id, $targetFormId)) { | |
return $error; | |
} | |
$fieldName = $field['name']; | |
if (empty($formData[$fieldName])) { | |
return $error; | |
} | |
$valueArray = explode('@', $formData[$fieldName]); | |
$inputDomain = array_pop($valueArray); | |
if (in_array($inputDomain, $blacklistDomains)) { | |
return [$errorMessage]; | |
} | |
return $error; | |
}, 10, 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment