• Resolved jpgoem

    (@jpgoem)


    Hello,

    The email field in Forminator allows for some validation of the email address, but apparently this is limited to basic syntax checking (presence of an @ and a period in the domain name).

    Are there possibilities to do further checks, such as checking the domain name and possibly even the recipient or username)?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @jpgoem

    Hope this message finds you well.

    Currently, there is no option to customize the email validation, however, our developers coded a snippet to check a list of forbidden domains:

    add_filter( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ){
    
    	$email_field = 'email-1';
    	$forbitten_public_emails = array( 'gmail', 'yahoo' );
    
    	$email = isset( $_POST[ $email_field ] ) ? $_POST[ $email_field ] : false;
    	if ( ! $email ) {
    		return $submit_errors;
    	}
    
    	list( $user, $domain ) = explode( '@', $email );
    
    	foreach ( $forbitten_public_emails as $forbitten_public_email ) {
    
    		if ( strpos( $domain, $forbitten_public_email ) !== false ) {
    		    $submit_errors[][ $email_field ] = __( 'Please avoid using gmail, yahoo etc and use a private email instead' );
    		    break;
    		}
    
    	}
    
    	return $submit_errors

    You will need to update these lines:

    $forbitten_public_emails = array( 'gmail', 'yahoo' );

    Replace gmail, yahoo, with the domains you want to block or verify.

    $email_field = ’email-1′;

    Replace the email-1 with your form email field tag.

    You might need to install it as a mu-plugin following the instructions on this link https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins.

    Best regards,
    Laura

    Thread Starter jpgoem

    (@jpgoem)

    Hi Laura,

    I am not looking to exclude “forbidden” domains. Thank you anyway for the research.

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