Prevent SPAM! – Use Google’s reCaptcha with Web-To-Lead Form

Prevent SPAM! – Use Google’s reCaptcha with Web-To-Lead Form

Last Updated on April 23, 2023 by Rakesh Gupta

A Lead in a marketing context, is a potential sales contact, an individual or organization, that expresses an interest in your products or services. Leads are typically captured through the referral of an existing customer, or directly through the company website (Using Web-to-Lead), etc. Usually, Leads are converted when they have been identified as qualified sales prospects. 

A Web-to-Lead Form is an essential component of marketing and sales automation. The Form is placed on a public website where you generate Leads from prospective customers who visit the site. From past couple of years, Salesforce has provided an out-of-the-box, Web-to-Lead feature to their customers. It is quite easy to setup and customize web form to capture leads for your organization. But what about SPAM prevention?

What is  Spam?

Spam is a method of submitting unwanted information to web forms. Unwanted information may be advertisements, links to offer pages, phishing URLs, and abusive texts. Spammers create bots to automatically find web forms and post advertisement links.

Where is Spam coming from?

To understand how to stop SPAM, first you need to understand that spam leads are created in two main ways:

  • Bots – automated software which will enter details in your forms on a rapid and mass scale.
  • Human – people deliberately entering fake details, either because they are time wasters or trying to sell something.

Until now, we have been using Validation Rule, Antispam question (something like What is 4+2?), etc. In Spring’17 release, Salesforce has added one exciting feature Web-to-Lead: reCAPTCHA Web Form Validation. Now it is possible to add Google reCAPTCHA to your Web-to-Lead Form using few clicks; code is no more required to implement it! Protect your site from spam and abusive activities by adding Google reCAPTCHA V2 to your Web-to-Lead Form. Let’s start with a use case. 

Business Use Case

Kristen Flanagan is working as a System administrator at Gurukul on Cloud. A month back, she has started her new job after completing Administrator certification. She received a requirement from her manager stating that, stakeholders are planning to capture Lead from the corporate website. For this, they want to use out-of-the-box Web-to-Lead Form. She also received a related requirement requesting her to enable spam filtering for the form. 

Solution for the Above Business Requirement

To solve the preceding requirement perform the following instructions: 

  1. Very first thing you need to do is register your website ( – where you are planning to host the Web-to-Lead Form) on Google reCAPTCHA to get the Site and Secret key. 
  2. To obtain Google reCAPTCHA 2.0 API keys, you need to sign up on You may need Google account to sign up. It will open a form, where you have to fill the data, to do this follow these steps:
    1. You can put anything on Label field as it is just for your notes. For current scenario enter Gurukul On Cloud Web-to-Lead as Label.
    2. The next step is to choose the type of reCAPTCHA. For current scenario select reCAPTCHA V2 it validates users with the “I’m not a robot” checkbox.
    3. Then you have to enter the domain name. This is simply asking you where are you planning to post your Web-to-Lead Form. For current scenario, we are going to host the Web-to-Lead Form on, and then, use as a domain. You can list more than one domain (one per line) without http(s)://. Also, keep in mind that your domain should end with TLD ( .com, org, .net)  for example – would be invalid and correct domain would be –
    4. Make sure to select the checkbox Accept the reCAPTCHA Terms of Service
    5. At the bottom, you will find a checkbox Send alerts to owners. You can select it, if you want Google to send you a report when Google finds something suspicious on your website. Finally, the signup page will look like the following screenshot:
    6. Once you are done, click on the Register button. It will be redirected to next page, which will have API keys and some other useful information. Keep this page open for a while as we will need to copy some elements from this page.Now we will create a web-to-lead form in Salesforce and use these keys in the form. 
  3. Navigate to Setup (Gear Icon)Setup | Feature Settings | Marketing | Web-to- Lead in Lightning Experience. 
  4. To create a new form from scratch that captures lead details on GurukulOnCloud site, click on the Create Web-to-Lead Form button, as shown in the following screenshot: 
  5. The next step is to select fields you want to include in your form. For current scenario, include these fields First Name, Last Name, Email, and City. 
  6. Now specify the  URL, to which users should be directed once they submit their information. For current scenario use this as Return URL
  7. If you want to add a reCAPTCHA widget to the lead submission form, then select Enable spam filtering check box. Then use the lookup dialog to specify reCAPTCHA API Key, as shown in the following screenshot: 
  8. What happens, when  Google reCAPTCHA servers are not available!? if you want to allow traffic then select Enable server fallback checkbox, it means all traffic from your website will be captured.
  9. At the end, the web-to-lead Form will look like the following screenshot:
  10. Click on the Generate button to get the HTML code. Copy the generated HTML code and provide it to your company’s webmaster to incorporate into your corporate website – for the current scenario, I am going to paste this code on GurukulOnCloud site.
  11. Click Finished.

It’s time to test the Form

To test the Web-to-Lead Form, open this URL in your browser and check the Google reCAPTCHA. It will look like the following screenshot:

Technical Editor and Proofreader: - Munira Majmundar

Please feel free to share it with your family, friends, and colleagues!

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

5 thoughts on “Prevent SPAM! – Use Google’s reCaptcha with Web-To-Lead Form

  1. Hi. Great article. How do you prevent the user from clicking the submit button without clicking on the Captcha? Without that, the Captcha doesn’t really serve a purpose. Thank you

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.