• Resolved redoan99

    (@redoan99)


    Hi, thanks a lot for this plugin. I want to set restriction on some email domain. But there is no option for that in forminator. Thats why I installed a plugin to do that. That plugin also has features like restricting user name or name etc. All those features are working fine with forminator. But the email restriction is not working. Here is the ss from that plugin. https://prnt.sc/dQLo2GfcXaPM
    There is an option ‘The name of the user_email field in registration form, leave it empty if the registration form is default’.
    Do I need any changes in this option to restrict emails?

    • This topic was modified 2 years, 10 months ago by Jan Dembowski.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @redoan99,

    Could we know which exact plugin are you using for such a feature? Unless the plugin offers compatibility with Forminator the chances for it to work out of the box are limited.

    As a workaround, you could try this custom snippet to restrict domains:

    <?php
    
    add_filter( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ){
    
    	$email_field = 'email-1';
    	$forbidden_public_emails = array( 'gmail.com', 'yahoo.com' );
    
    	$email = isset( $_POST[ $email_field ] ) ? $_POST[ $email_field ] : false;
    	if ( ! $email ) {
    		return $submit_errors;
    	}
    
    	list( $user, $domain ) = explode( '@', $email );
    
    	foreach ( $forbidden_public_emails as $forbidden_public_email ) {
    
    		if ( strpos( $domain, $forbidden_public_email ) !== false ) {
    		    $submit_errors[][ $email_field ] = __( 'Forbidden email. Please try using a different email.' );
    		    break;
    		}
    
    	}
    
    	return $submit_errors;
    }, 20, 3 );
    

    In the above code, you’ll need to edit the following line to your domains that need to be restricted.

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

    You can implement the above code as a mu-plugins. Please check this link on how to implement the above code as a mu-plugins:
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Kind Regards,
    Nithin

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @redoan99 ,

    We haven’t heard from you for a while now, so it looks like the code worked for you.

    Feel free to re-open this ticket if needed.

    Kind regards
    Kasia

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Email restriction’ is closed to new replies.