Created
February 24, 2022 06:37
-
-
Save dannyfoo/2f4bd43e4a4f9e17687cf5ed0719b2c1 to your computer and use it in GitHub Desktop.
Restrict email domains in FluentForms
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
/** | |
* Source: https://fluentforms.com/docs/limit-email-domains-in-fluent-forms-form-submission/ | |
**/ | |
add_filter('fluentform_validate_input_item_input_email', function ($error, $field, $formData, $fields, $form) { | |
/* | |
* add your accepted domains here | |
* Other domains will be failed to submit the form | |
*/ | |
$targetFormId = 1; | |
$acceptedDomains = ['gmail.com', 'hotmail.com', 'yahoo.com']; | |
$errorMessage = 'The provided email domain is not accepted'; | |
if ($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, $acceptedDomains)) { | |
return [$errorMessage]; | |
} | |
return $error; | |
}, 10, 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment