OhhMuaOhhMua
  • Home
  • Hosting
    • Best Web Hosting
    • Free Web Hosting
    • VPS Hosting
  • WordPress
    • Solutions & Troubleshooting
    • Installation & Setup
    • Themes & Plugins
    • Security
  • Build PC
    • High-end Builds
    • Mid-range Builds
    • Entry-level Builds
  • Computer Tips
    • Gaming Errors & Solutions
    • PC Troubleshooting
    • Hardware Tips
    • Computer Hardware
  • Coupons & Deals
  • Tools
    • veo3 prompt generator
Reading: Most Effective Ways to Prevent SPAM in Contact Form 7
Notification Show More
OhhMuaOhhMua
  • Computer Tips
  • Hosting
  • WordPress
Search
  • Home
  • WordPress
    • Installation & Setup
    • Security
    • Solutions & Troubleshooting
    • Themes & Plugins
    • Troubleshooting
  • Hosting
    • Free Web Hosting
    • VPS Hosting
    • Best Web Hosting
  • Computer Tips
    • PC Troubleshooting
    • Gaming Errors & Solutions
    • Computer Hardware
  • Coupons & Deals
  • veo3 prompt generator
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

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

Cannot Fetch Sitemap in Google Search Console

Discovered – Currently Not Indexed in Google Search Console: What It Means & How to Fix It

Why 2 Backlinks per Article Might Be Killing Your SEO

What is Obsidian? Why Developers Love This Note-Taking App

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

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

June 5, 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
How to Check Motherboard Compatibility
Computer Hardware

Intel 14th Gen CPU Upgrade: How to Check Motherboard Compatibility

July 13, 2025
admin wordpress dashboard
Themes & Plugins

Introduction to the WordPress Dashboard: Features, Tools, and Navigation

April 25, 2025
GTA6 Trailer 2
Gaming Errors & Solutions

GTA6 Trailer 2: The Hidden Easter Eggs You Didn’t Notice

May 8, 2025
White Violet Ice pc gaming
High-end Builds

White Violet Ice Gaming PC Build: Icy Beauty with Outstanding Performance

July 20, 2025
Previous Next

You Might Also Like

Optimize WordPress
Solutions & Troubleshooting

Want Faster Load Times? Optimize WordPress This Way

Admin (Nghia Vo) Admin (Nghia Vo) May 16, 2025
My Google Discover traffic skyrocketed after I did these 10 things
Solutions & Troubleshooting

My Google Discover traffic skyrocketed after I did these 10 things

Admin (Nghia Vo) Admin (Nghia Vo) May 14, 2025
How to Add a Read More to Product Descriptions in WooCommerce
Solutions & Troubleshooting

How to Add a “Read More” and “Show Less” Button to Product Descriptions in WooCommerce

Admin (Nghia Vo) Admin (Nghia Vo) May 5, 2025
WordPress Covers Every Website Type
Solutions & Troubleshooting

Blog, E-Commerce, or Forum? WordPress Covers Every Website Type!

Admin (Nghia Vo) Admin (Nghia Vo) April 29, 2025
Optimized Pagination thumbnail
Solutions & Troubleshooting

How I Optimized Pagination and Skyrocketed Traffic

Admin (Nghia Vo) Admin (Nghia Vo) April 28, 2025
How to Pick the Ideal Blogging Platform for Your Needs
Solutions & Troubleshooting

How to Pick the Ideal Blogging Platform for Your Needs

Admin (Nghia Vo) Admin (Nghia Vo) April 1, 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
Welcome Back!

Sign in to your account

Lost your password?