• Resolved talaris

    (@talaris)


    Hello,

    ist there a way to whitelist Mail-Domains so the user who fills the form can only type in a mail-address with for example @wordpress.org?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Laura – WPMU DEV Support

    (@wpmudev-support8)

    Hi @talaris

    I hope you’re well today!

    There is no such feature currently but this custom code – with a slight modification – should help:

    https://gist.github.com/adczk/30c20df28ec739ccc87ebb98dad20d50

    To add it to the site and make it work they way you need:

    1. create an empty file with a php extension (e.g. “forminator-allow-email-domains-only.php”) in the “/wp-content/mu-plugins” folder of your site’s WordPress install on your server

    2. copy raw code form that link and past it into the file

    3. now to configure the code:

    a) in this line

    $mail_forms = array( 1445 );

    replace 1445 with an ID of your form (or comma-separated list of IDs); form ID is the number you see in form’s shortcode

    b) in this line

    $mail_field = 'email-1';

    adjust e-mail field ID if needed; this field will be checked

    c) in this line

    $error_msg = 'Invalid e-mail address!';

    customize your error message

    d) and in this part

    $disallowed = array(
    		'@gmail.com',
    		'@yahoo.com'
    	);

    set e-mail domains that you want to allow;

    Note that it says “disallowed” but don’t worry about it. This code was initially meant to block selected e-mail domains but below is a way to modify it to work opposite way – block all except those defined in above code.

    c) now let’s add the modification; replace this line

    if ( stristr( $email, $to_check) ) $submit_errors[][$mail_field] = $error_msg;

    with this

    if ( ! stristr( $email, $to_check) ) $submit_errors[][$mail_field] = $error_msg;

    4. save the file and test it.

    It should now issue your custom error below the e-mail field on the form each time you use e-mail address from a different domain than any of the domains specified in the code.

    Best regards,
    Adam

    Thread Starter talaris

    (@talaris)

    Hi Adam,

    thank you!

    the folder mu-plugins did not exist, but after creating it, it worked like a charm.

    Greetings
    Dennis

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘E-Mail Whitelist’ is closed to new replies.