Ban Email Addresses Or Domains Name in Fluent Forms Form Submission

Ban Email Domains (Ban Particular Domains) in Fluent Forms Form Submission This snippet will for your email fields where it will ban certain domains. Please check both available snippet and use which is applicable for you. Don’t forget to change the values where it mentioned OR Thank You.

Ban Email Domains (Ban Particular Domains) in Fluent Forms Form Submission

This snippet will for your email fields where it will ban certain domains. Please check both available snippet and use which is applicable for you.

Don’t forget to change the values where it mentioned

Function.php
/*
 * Snippet: 1
 * This will apply for all the forms in your site
 */
add_filter('fluentform_validate_input_item_input_email', function ($error, $field, $formData, $fields, $form) {
    /*
     * add your not accepted domains here
     * The mentioned domains will be failed to submit the form
     */
    $invalidDomains = ['gmail.com', 'hotmail.com', 'test.com']; // You may change here
    $errorMessage = 'The provided email domain is not accepted'; // You may change here

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

    $valueArray = explode('@', $formData[$fieldName]);
    $inputDomain = array_pop($valueArray);

    if (in_array($inputDomain, $invalidDomains)) {
        return [$errorMessage];
    }
    return $error;
}, 10, 5);

OR

/*
 * Snippet: 2
 * This will apply for only form id: 12
 */
add_filter('fluentform_validate_input_item_input_email', function ($error, $field, $formData, $fields, $form) {
    /*
     * add your not accepted domains here
     * The mentioned domains will be failed to submit the form
     */
    // You may change the following 3 lines
    $targetFormId = 12;
    $invalidDomains = ['gmail.com', 'hotmail.com', 'test.com']; // You may change here
    $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, $invalidDomains)) {
        return [$errorMessage];
    }
    return $error;

}, 10, 5);

Thank You.

Previous Code

Create a new WordPress Administrator User via functions.php & FTP Code

Can not delete User/admin/manager Change your Need ...

Next Code

Add Post type to search results filtering by ACF meta value

search and filter pro tutorial,search and filter p ...

Leave a Reply

Your email address will not be published. Required fields are marked *

If you find it useful

buymeacoffee

ACF

Blog

Elementor

HTML JQuery

PHP

WordPress

Disable WooCommerce Payment Gateway for Specific Country WordPress

To disable a payment gateway for a specific countr ...

How to Create a Dropdown Box to Sorting Posts in WordPress

With Search by Category:custom-sort-form.php Witho ...

Create a new WordPress Administrator User via functions.php & FTP Code

Can not delete User/admin/manager Change your Need ...

top