Enjoy 70% OFF in PHP Scripts, WordPress Themes and more... Get Offer >

Anti-spam for Contact Form 7 plugin

Anti-spam for Contact Form 7 plugin

Hello everyone!

If you've ever used the Contact Form 7 plugin to create contact or order forms, you may have encountered situations where many customers leave their information, but when you call them, it turns out they aren’t real customers. This is a common issue, especially when building websites for clients, and spam is quite rampant with open-source CMS platforms. If you're using WordPress and the Contact Form 7 plugin, how can you prevent this problem? In this guide, I’ll show you how to solve it.

Preventing Spam for Contact Form 7 Using Akismet Plugin

Akismet is an automatic spam-filtering tool. The name Akismet comes from combining "Automattic" (the company behind Akismet) and "Kismet." It was created by Matt Mullenweg, the founder of the WordPress community. Akismet catches spam comments and pingbacks through its algorithm, which learns from its mistakes and from actions taken by the user community.

For instance, if a number of websites report a certain comment as spam, Akismet will analyze and recognize similar content as spam in the future.

Step 1: Download Akismet Anti-Spam Plugin

Akismet is possibly the best way to protect your blog from spam. Your site will be fully configured and protected. You’ll need an API key to use Akismet. If you're using it on a personal blog, you can get a free API key. For corporate or commercial websites, there are paid subscription options.

Step 2: Using Akismet with Contact Form 7

In Contact Form 7, there are three key fields: your-name, your-email, and your-url. Akismet can be used to filter these fields. Here's how you can do it:

Go to the form you want to filter spam from, edit one of the fields as shown below, and save it.

Filter spam for the name field:

[text* your-name akismet:author]

Filter spam for the email field:

[email* your-email akismet:author_email]

Filter spam for the URL field:

[url* your-url akismet:author_url]

To deploy Akismet in Contact Form 7, you can use one or more of these options. For the best results, it’s recommended to use as many options as possible.

Step 3: Test the Spam Filter

To test if the spam filter is working correctly, try entering "viagra-test-123" in the name field (akismet

) or "akismet-guaranteed-spam@example.com" in the email field (akismet) and submit the form. These terms are used specifically for testing, and Akismet should return a "spam" response. If it’s working as expected, you’ll see an error message saying "An error occurred while submitting," surrounded by an orange border.

 

Validating Phone Numbers Against Spam in Contact Form 7

Another field that is often spammed in Contact Form 7 is the phone number field. Here’s how you can validate the phone number field to match Vietnamese phone numbers, ensuring that it starts with 0 and contains 10 digits.

1. Code for requiring 10 digits:
The code is:

[tel* your-phone minlength:10 maxlength:10]

In this code:

  • minlength:10 specifies the minimum number of digits allowed.
  • maxlength:10 specifies the maximum number of digits allowed.

2. Code for requiring the number to start with 0 and match Vietnam’s carrier numbers:
To validate the phone number in Contact Form 7, add the following code to your theme’s or child theme’s functions.php file.

This will check all the valid carrier prefixes in Vietnam and only allow correct numbers to be submitted.

Good luck!

Comments (0)
Login or create account to leave comments

We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies

More