Sometimes even after using Google ReCaptcha and other spam protections on the website forms, we tend to receive submissions related to promotional or marketing events (cold campaigns), spam submissions containing obscene, vulgar, or otherwise offensive content. In such cases, if you are using Gravity Forms on your website. you can use the following approach to block all such form submissions. You’ll explore to prevent spam form submissions using stop or disallowed keywords.
Table of Contents
In this blog, you’re going to know what gravity forms are, steps to prevent spam form submissions using stop words or disallowed keywords, and the benefits to do that.
What are Gravity Forms?
Gravity Forms is a plugin for the WordPress content management system that allows users to create and manage forms on their website. The plugin includes a variety of form fields and customization options, as well as the ability to integrate with other popular online services, such as PayPal and MailChimp. It also allows you to create advanced forms like surveys, contact forms, registration forms and more.
The forms can be used for various purposes like creating leads, collecting payment or even for creating a custom quiz. It is one of the most popular form plugin for WordPress.
Related: How to Implement Infinite Pagination in WordPress?
How to Prevent Spam Form Submissions Using Stop Words or Disallowed Keywords?
Here are some methods that can be applied:
1. Install a spam prevention plugin
There are several spam prevention plugins available for WordPress, such as Akismet, that can automatically check submitted data for common spam keywords and phrases.
Related: Top 10 SEO Plugins for WordPress Website
2. Create a list of stop words and disallowed keywords
Identify the most common spam keywords and phrases that you have received in the past and add them to your plugin’s settings or to your own list.
3. Implement a CAPTCHA or reCAPTCHA
Add a CAPTCHA or reCAPTCHA to your form to make it more difficult for bots to submit it.
4. Use Honeypot technique
Add a hidden field to your form that is not visible to the user. If this field is filled in, it is likely that the submission is coming from a bot and it can be blocked.
5. Regularly review and update your list of stop words and disallowed keywords
Keep an eye on new spam submissions, and update your list of stop words and disallowed keywords as necessary.
Also read: How to Prevent Your Website PDF File From Getting Indexed in Google?
6. Monitor the Form Submissions
Make sure to regularly check the submissions you receive to see if any spam messages are slipping through. If you do find any, add the keywords or phrases used to your list of stop words and disallowed keywords.
By following these steps, you can effectively reduce the number of spam form submissions on your website and keep your data clean.
To stop form submissions with Profanity (Bad Words), you need to add all the possible stop words in the WP backend – disallowed comment keywords.
Settings >> Discussion
Click on Disallowed Comments Keys and, add all such words which you don’t want in your form field submissions.
Once you’re done adding all the stop words.
Open your themes functions.php file and add the below script at the bottom of the script before closing of any PHP tag.
/*
* Search bad words in the entered string
*/
function strpos_arr($haystack, $needle) {
if(!is_array($needle)) $needle = array($needle);
foreach($needle as $what) {
if(($pos = stripos($haystack, $what))!==false) return $pos;
}
return false;
}
/*
* Bad words validation function
*/
add_filter('gform_validation', 'smartland_spam_validation');
function smartland_spam_validation($validation_result){
$form = $validation_result["form"];
/* $stop_words = array(
'outsource',
'Sir/Madam',
'Sir/ Madam',
'Sir / Madam',
'Sir /Madam',
'long term relationship',
); */
$stop_words = get_option('disallowed_keys');
$stop_words = explode("\n", $stop_words);
$stop_id = array();
foreach($_POST as $id => $post)
{
if(strpos_arr($post, $stop_words)!==false)
{
$stop_id[] = $id;
}
}
if(sizeof($stop_id) > 0)
{
$validation_result['is_valid'] = false;
foreach($form['fields'] as &$field)
{
foreach($stop_id as $id)
{
$the_id = (int) str_replace('input_', '', $id);
if($field['id'] == $the_id)
{
$field['failed_validation'] = true;
$field['validation_message'] = 'Please do not send us unsolicited messages';
}
}
}
}
//assign modified $form object back to the validation result
$validation_result["form"] = $form;
return $validation_result;
}
After you’re done adding the above piece of code in your functions.php. You can now test the forms on the website which are built using gravity forms.
Related: Want to implement a contact us form in shopify?
Benefits to Prevent Spam Form Submissions
There are several benefits to preventing spam form submissions, including:
1. Protecting personal information
Spam form submissions can often be used to gather personal information, such as email addresses or phone numbers. Preventing spam submissions can help protect this information from being collected and used for unwanted purposes.
2. Improving user experience
Spam form submissions can make it difficult for legitimate users to submit forms, as they may have to sift through a large number of spam submissions to find the real ones. Preventing spam submissions can improve the user experience by making it easier for legitimate users to submit forms.
3. Saving time and resources
Spam form submissions can take up a lot of time and resources to review and process. Preventing spam submissions can save time and resources that can be better used elsewhere.
4. Improving the deliverability of important messages
Spam submissions can cause legitimate messages to be lost or filtered out, which can be problematic in certain situations. Preventing spam submissions can help ensure that important messages are delivered and received.
5. Increasing the security of a website
Spam submissions can be used to exploit vulnerabilities in a website’s forms, potentially allowing attackers to gain access to sensitive information. Preventing spam submissions can help increase the security of a website by closing these vulnerabilities.
Also read: How to Enable cc Field in Gravity Form Email Notifications?
Conclusion
In conclusion, prevent spam form submissions using stop words or disallowed keywords is an important task for any website owner. Spam submissions can clutter your data and make it difficult to find legitimate submissions.
By using a spam prevention plugin, creating a list of stop words and disallowed keywords, implementing a CAPTCHA or reCAPTCHA, using Honeypot technique, and regularly monitoring and updating your list of stop words and disallowed keywords, you can effectively reduce the number of spam form submissions on your website.
This will help keep your data clean and make it easier to identify and respond to legitimate submissions. With the help of these simple steps, you can effectively keep your form submissions spam-free.