OhhMuaOhhMua
  • Home
  • WordPress
    • Solutions & Troubleshooting
    • Installation & Setup
    • Themes & Plugins
    • Security
  • Tools
    • veo3 prompt generator
  • Our Team
  • Hosting
    • Best Web Hosting
    • Free Web Hosting
    • VPS Hosting
Reading: Most Effective Ways to Prevent SPAM in Contact Form 7
Notification Show More
OhhMuaOhhMua
  • WordPress
  • Entry-level Builds
  • High-end Builds
  • Mid-range Builds
  • Hardware Tips
  • Software Tips
Search
  • Home
  • WordPress
    • Installation & Setup
    • Security
    • Solutions & Troubleshooting
    • Themes & Plugins
  • Tools
    • veo3 prompt generator
  • Our Team
    • Hosting
Follow US
Copyright © 2024 ohhmua. All rights reserved.
OhhMua > Blog > WordPress > Solutions & Troubleshooting > Most Effective Ways to Prevent SPAM in Contact Form 7
Solutions & Troubleshooting

Most Effective Ways to Prevent SPAM in Contact Form 7

Admin (Nghia Vo)
Last updated: September 10, 2024 4:27 pm
Admin (Nghia Vo)
Share
4 Min Read
Most Effective Ways to Prevent SPAM in Contact Form 7
Most Effective Ways to Prevent SPAM in Contact Form 7
SHARE
Contents
Preventing Spam by Checking If Users Have ScrolledConclusion:

One of the most frustrating issues when adding a form to your website is dealing with relentless spam from bots. If you’ve been receiving spam emails from Contact Form 7 (CF7) constantly, despite trying various solutions, this article will guide you on how to effectively block and stop those automated spam submissions once and for all.

Most Effective Ways to Prevent SPAM in Contact Form 7
Most Effective Ways to Prevent SPAM in Contact Form 7

Recently, someone reached out to me, struggling with CF7 spam even after using Akismet, reCAPTCHA, Wordfence .Luckily, I had a custom-made code that I shared with them, and it worked wonders! They reported that the spam stopped entirely, so I’m excited to share this solution with you as well. Give it a try, and say goodbye to CF7 spam!

Preventing Spam by Checking If Users Have Scrolled

I believe this is one of the simplest and most effective ways to prevent spam. It’s easy for users and limits auto-spam submissions.

Mechanism: Forms are usually placed in the middle or at the bottom of the website, so users have to scroll down to reach the form and enter their information before submitting, right? Therefore, we can track how much the user has scrolled, and if it reaches a certain point that seems appropriate, we allow the form to be submitted.

Advantages:

  • It doesn’t annoy users.
  • It’s simple and doesn’t affect the form’s interface.

Disadvantages:

  • At the moment, I haven’t found any downsides! 😀

Implementation: Simply add the following code to wp-content/themes/{your-theme}/functions.php.

/*
 * Check spam for CF7 by scroll
 * Author: ohhmua.com
 */
add_filter('wpcf7_form_elements', 'devvn_check_scroll_form_cf7');
function devvn_check_scroll_form_cf7($html){
    $html = '<div style="display: none"><p><span class="wpcf7-form-control-wrap" data-name="devvn-scroll"><input size="40" class="wpcf7-form-control wpcf7-text" aria-invalid="false" value="0" type="text" name="devvn-scroll"></span></p></div>' . $html;
    return $html;
}

add_action('wpcf7_posted_data', 'devvn_check_scroll_form_cf7_vaild');
function devvn_check_scroll_form_cf7_vaild($posted_data) {
    $submission = WPCF7_Submission::get_instance();
    $scroll = isset($posted_data['devvn-scroll']) ? intval($posted_data['devvn-scroll']) : 0;
    // If the form is placed near the top of the page, replace 5000 with a smaller number, e.g., 200
    if (!$scroll || $scroll <= 5000) {
        $submission->set_status( 'spam' );
        $submission->set_response( 'You are a spammer' );
    }
    unset($posted_data['devvn-scroll']);
    return $posted_data;
}

add_action('wp_footer', function (){
    ?>
    <script>
        const scrollInputs = document.querySelectorAll('input[name="devvn-scroll"]');
        if(scrollInputs.length > 0) {
            let accumulatedScroll = 0;
            function devvnCheckScroll() {
                accumulatedScroll += window.scrollY;
                scrollInputs.forEach(input => {
                    input.value = accumulatedScroll;
                });
                // If the form is placed near the top of the page, replace 6000 with a smaller number, e.g., 300
                if (accumulatedScroll >= 6000) {
                    window.removeEventListener('scroll', devvnCheckScroll);
                }
            }
            window.addEventListener('scroll', devvnCheckScroll);
        }
    </script>
    <?php
});

In the code, there are two values, 5000 and 6000, as I’ve noted directly in the code. These numbers depend on the position of the form on your website, but I believe they are fine as-is. You can adjust them as needed.

Conclusion:

That’s it! These are the methods I wanted to share with you to prevent spam. I hope this helps you block those annoying spam bots!

480520387 657957633334779 6814038772835954285 n
Admin (Nghia Vo)

Hi, I’m Nghia Vo: a computer hardware graduate, passionate PC hardware blogger, and entrepreneur with extensive hands-on experience building and upgrading computers for gaming, productivity, and business operations.
As the founder of Vonebuy.com, a verified ecommerce store under Vietnam’s Ministry of Industry and Trade, I combine my technical knowledge with real-world business applications to help users make confident decisions.

I specialize in no-nonsense guides on RAM overclocking, motherboard compatibility, SSD upgrades, and honest product reviews sharing everything I’ve tested and implemented for my customers and readers.

You Might Also Like

Headless vs Traditional WooCommerce: Which Architecture Wins?

Can AI Agents Safely Access Your WordPress Site?

Is WordPress Dead or Still Powering the Web in 2026?

WordPress 6.9.2 Disaster: Why You Should Never Auto-Update Immediately

Headless WordPress Explained: Is It Right for Your Site?

TAGGED:Block spam for Contact Form 7How to Stop Contact Form Spam in WordPressPrevent spam for Contact Form 7
Share This Article
Facebook Twitter Email Print
By Admin (Nghia Vo)
Follow:
Hi, I’m Nghia Vo: a computer hardware graduate, passionate PC hardware blogger, and entrepreneur with extensive hands-on experience building and upgrading computers for gaming, productivity, and business operations. As the founder of Vonebuy.com, a verified ecommerce store under Vietnam's Ministry of Industry and Trade, I combine my technical knowledge with real-world business applications to help users make confident decisions. I specialize in no-nonsense guides on RAM overclocking, motherboard compatibility, SSD upgrades, and honest product reviews sharing everything I’ve tested and implemented for my customers and readers.
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Trending

My Google Discover traffic skyrocketed after I did these 10 things
Solutions & Troubleshooting

My Google Discover traffic skyrocketed after I did these 10 things

May 14, 2025
Most Effective Ways to Prevent SPAM in Contact Form 7
Solutions & Troubleshooting

Most Effective Ways to Prevent SPAM in Contact Form 7

September 10, 2024
How to Pick the Ideal Blogging Platform for Your Needs
Solutions & Troubleshooting

How to Pick the Ideal Blogging Platform for Your Needs

April 1, 2025
Create a Simple Incrementing Number Effect with HTML and JavaScript 2
Solutions & Troubleshooting

Create a Simple Incrementing Number Effect with HTML and JavaScript

September 17, 2024
Optimize WordPress
Solutions & Troubleshooting

Want Faster Load Times? Optimize WordPress This Way

May 16, 2025
How to Quickly Delete Spam Comments Using WP CLI with Terminal in WordPress
Solutions & Troubleshooting

Delete Thousands of Spam Comments in 1 Second with WP CLI

September 12, 2024
Previous Next

You Might Also Like

WordPress 7.0 Finally Fixes 20 Years of Painful Collaboration Problems
Solutions & Troubleshooting

WordPress 7.0 Finally Fixes 20 Years of Painful Collaboration Problems

Admin (Nghia Vo) Admin (Nghia Vo) March 9, 2026
HETZNER HOSTING
Solutions & Troubleshooting

Why Hetzner Might Not Be the Right Choice for Beginners

Admin (Nghia Vo) Admin (Nghia Vo) March 7, 2026
wordpress speed 2026
Solutions & Troubleshooting

WordPress Speed in 2026: The Only Hosting Checklist You Need

Admin (Nghia Vo) Admin (Nghia Vo) March 7, 2026
What Happens When Web Hosting Companies Get Acquired
Solutions & Troubleshooting

What Happens When Web Hosting Companies Get Acquired

Admin (Nghia Vo) Admin (Nghia Vo) March 6, 2026
wordpress shortcode 1
Solutions & Troubleshooting

WordPress Shortcodes: Complete Guide to Dynamic Content

Admin (Nghia Vo) Admin (Nghia Vo) March 4, 2026
How to Make Google Understand and Value Your Content
Solutions & Troubleshooting

SEO in the Age of AI: How to Make Google Understand and Value Your Content

Admin (Nghia Vo) Admin (Nghia Vo) June 5, 2025
Previous Next
newsletter featured

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!

Follow US on Social Media

Facebook Youtube Steam Twitch Unity

Copyright © 2024 ohhmua. All rights reserved.

OhhMua

Information

  • About
  • Terms & Conditions
  • Privacy Policy
  • Editorial Standards
Welcome Back!

Sign in to your account

Lost your password?