Requiring reCaptcha Verification v2
Many companies today rely on Google reCaptcha verification for their Salesforce Web-to-Lead and Web-to-Case forms to help avoid spam Leads and Cases from being generated. Salesforce does provide out-of-the-box functionality to include reCaptcha verification on both forms. This functionality works by preventing a Lead or Case from being created in Salesforce if a customer has not gone through the reCaptcha verification process before submitting the form.
However, standard functionality will still allow a customer to click the Submit button and submit the form even if reCaptcha verification has not been completed. The confusing part here is that even though the customer has submitted the form, it hasn’t actually been submitted to Salesforce because reCaptcha verification was not done.
Fortunately, there is a great way to handle this and eliminate customer confusion. The provided solution will only allow a customer to click Submit on the web form after they have successfully completed reCaptcha verification.
Start by adding additional HTML markup to the web form and add script to the JavaScript file for the web page. This will allow you to make reCaptcha verification required to click Submit.
In this example, we added the data-callback function to the HTML file inside the g-reCaptcha tag, along with some additional text inside the tag for the Submit button. The data-callback is a function Google provides to help with reCaptcha verification. The HTML file should look something like this:
As seen above, you can initially set the Submit button to a “disabled” status.
You will also need to add a script for the data-callback function to the JavaScript file used for the web page: