Elementor Forms – Allow Only Business Email Address in Email Field

Please find below a step-by-step guide on how to use Elementor Forms in such a way that only business email addresses are accepted as Email Field entries. The following is how to perform this step. There will be nothing more to it than following these simple steps.

Here's how to use Elementor Forms to allow only business email addresses to be entered in the Email Field. Here's how to do it. You simply have to follow the simple steps below!

Your website should have the following configurations in order for it to function properly:

  • Hello child theme or any other child theme (recommended)
  • Elementor Pro
  • Elementor forms API

The code for forms API

Elementor Pro is an extension of Elementor that adds new features to the core of the application. As part of the Forms API, you have the ability to filter and validate content, implement webhooks, execute custom code and accomplish a lot more.

Form Field Validation Action

elementor_pro/forms/validation/{$field_type}

It is a POST request which has the form action in it after the forms module has been loaded. Then you can therefore validate the different fields individually.

This hook's name, $field_type, is made up of the field type in the dynamic portion of the hook's name.

ArgumentTypeDescription
fieldArrayThe submitted field.
recordForm_RecordThe record was submitted.
ajax_handlerAjax_HandlerThe Ajax Handler component.
// Validate the email fields for valid domains
add_action( 'elementor_pro/forms/validation/email', function( $field, $record, $ajax_handler ) {
// Please include the email domains you would like to block in this list
$invalidDomains = ["@gmail.","@yahoo.","@hotmail.","@live.","@aol.","@outlook."];
	
	// email validation
	foreach($invalidDomains as $domain){
		if(strpos($field['value'], $domain) !== false){
    	$ajax_handler->add_error( $field['id'], "Must be Business email." ); 
		}
	}
}, 10, 3 );

Categories

Recent Posts

June 4, 2022
Elementor Forms – Allow Only Business Email Address in Email Field

Tags

Would you like to 
receive more WordPress 
tricks?

You can tell us anything you want and we'll make it happen. Whatever it takes, whatever it seems like it will be.
Services
Resources
Social Media
Copyright © 2022. All rights reserved.
Privacy Policy | Terms & Condition