Stop Spam on Elementor Forms

Picture of Robert Lee

Robert Lee

Owner & Designer
of Cheerful Media

How to stop spambot spam on Elementor forms with a simple PHP script.

Elementor Page Builder is one of the most popular WordPress page builders, with millions of websites relying on Elementor code to do what is needed.

But, getting spam on email forms when using Elementor native forms is just one of those things that happens. You can fight it with powerful anti-spam plugins (that cost money) or you can just give up on 100% spam filtering.

Until now.

Install this script in the “functions.php” file within your active theme code pages, and when it’s set up properly, you’ll be spam free when a submission is made using the properly set up Elementor form.

Here’s the code you’ll need to copy and paste into your “functions.php” page:

				
					// Validate confirmation email 

add_action( 'elementor_pro/forms/validation', function ( $record, $ajax_handler ) { 

$form_name = $record->get_form_settings( 'form_name' );

// Replace MY_FORM_NAME with the name you gave your form

  if ( 'MY_FORM_NAME' !== $form_name ) {
    return;
  }

//Replace MY_FIELD_ID_1 to match the field's Advanced > Field ID

  $first_email_field = $record->get_field( [
    'id' => 'MY_FIELD_ID_1'
  ] );

//Replace MY_FIELD_ID_2 to match the field's Advanced > Field ID

  $second_email_field = $record->get_field( [
    'id' => 'MY_FIELD_ID_2'
  ] );

//Make sure your field ID's are set to match these in each field's Advanced > Field ID
	if ( $first_email_field['MY_FIELD_ID_1']['value'] !== $second_email_field['MY_FIELD_ID_2']['value'] ) {
		$ajax_handler->add_error( $second_email_field['MY_FIELD_ID_2']['id'], 'Confirmation Email must match the Email field' );
	}

}, 10, 2 );
				
			

Setting up your Spam-free Elementor Form

Locate your “functions.php” page. It will be found at “/wp-content/themes/name of your active theme/functions.php”

Download your unchanged “functions.php” page.

Edit the downloaded page to include the code above, as shown below:

Replace “MY_FORM_NAME” with the form name you are using for your form (at the top of the form builder widget”).

Replace “MY_FIELD_ID_1” to a friendly advanced field ID, such as “email1”, you find this under the “Advanced” tab in the form builder for each separate form field. This is the email people submit to you when filling in the form.

“Replace MY_FIELD_ID_2” to match the field’s Advanced > Field ID, such as using “email_confirm”. This is the email that people fill out to confirm their email address is correct. Spambots will not complete this field, eliminating their spam submissions to your Elementor form.

 

Save and upload your new “functions.php” form, be certain to overwrite the exiting page.

 

Test your form.

If you run into an issue, please post a question on my Facebook page.

Share This Post:

Facebook
Twitter
LinkedIn
Email
Continue Reading

More Articles

SEO and UX Design

SEO and UX Design

When you start analyzing a website you need to start by understanding the SEO and UX Design decisions that were made.

Search Engine Optimization in Newmarket

Search Engine Optimization Newmarket

Understanding the needs of the business and client and the intent of potential website visitors and how current website content brings them together requires a solid starting plan that can be adjusted as results become evident.