Skip to content

Instantly share code, notes, and snippets.

@reachkamrul
Created August 3, 2021 17:08
Show Gist options
  • Save reachkamrul/d78e438e79f9253ec0640d76f9408e37 to your computer and use it in GitHub Desktop.
Save reachkamrul/d78e438e79f9253ec0640d76f9408e37 to your computer and use it in GitHub Desktop.
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 = 20;
$acceptedDomains = ['gmail.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