Skip to content

Instantly share code, notes, and snippets.

@gmmedia
Last active February 6, 2023 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmmedia/e005cb1139c7e049d094b6741c36cfb3 to your computer and use it in GitHub Desktop.
Save gmmedia/e005cb1139c7e049d094b6741c36cfb3 to your computer and use it in GitHub Desktop.
FluentForms - Email Blacklist - Specific Forms
<?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