Google Form customization that we previously implemented in response to a request to switch a website's contact form over to Google Forms.
We have compiled these into a column, and we are happy to see that many people have been referring to it. Thank you very much!
Pitfalls to Watch Out for When Building Your Forms with Google Forms
Implementing a Confirmation Screen for Google Form Customization
Recently, we received an inquiry asking whether there are any measures against the large volume of spam emails being sent.
As the third installment of our Google Form column, this article summarizes spam protection measures for Google Form customization.
The first idea that came to mind as a countermeasure was whether we could implement reCAPTCHA, a free security service provided by Google?
However,
Google Forms does not have a standard setting or toggle such as "Enable reCAPTCHA." There are no such options in the form editing screen either, and the correct understanding is that this is not a feature officially provided by Google.
That is what we were told. Upon further investigation, it appears that reCAPTCHA in Google Forms functions at Google's discretion, and it is unclear whether the reCAPTCHA mark will appear or not!
In the first place, customizing a Google Form requires putting field IDs such as entry.386122698 into the HTML, so everything is exposed in plain text. Once someone has this URL and the entry IDs, it is technically possible to send a POST directly to formResponse from a simple script using curl or Python's requests, without ever opening the page in a browser.
In fact, much of the spam hitting Google Forms appears to follow this pattern of bypassing the page and hitting the endpoint directly. Adding reCAPTCHA doesn't help with direct POST requests unless the token is verified on the server side, such as in GAS, so it is not a fundamental solution.
That said, there are countermeasures!
Many actual spam bots are general-purpose bots that find a contact form, auto-fill it, and submit it by rendering the page and sending the form through the DOM.
Against this type of bot, controlling the submit button with JavaScript is somewhat effective. For greater accuracy, combining several of these measures is recommended. All of them can be implemented by changing only the HTML file, without touching the Google Form or the GAS side.
Reference: [reddit] How can I prevent bots from spamming my Google Form and flooding my email?
1. Generate and display a random addition problem with JavaScript.
This is a simple arithmetic challenge using randomly generated addition of two numbers via Math.floor(Math.random()*9)+1. Each time the page loads, JavaScript generates and displays a problem such as "3 + 5 = ?", and the submit button stays disabled until the user enters the correct answer.
This adds a bit of effort for users, but it tends to catch general-purpose bots that ignore the visual UI and go straight for the submit button.
2. Automatic detection using a honeypot field (an invisible input field)
Place a single input field off-screen using CSS so it is invisible to human users. Humans will never interact with this field, but bots that mechanically fill in every field in a form will also populate it. If this field contains a value on submission, the submission is canceled.
This method is effective against bots that mechanically fill in every input field on a form, whether visible or not. Since this type of bot is very common, this countermeasure can be expected to help considerably.
Each method detects different types of bots, so combining both reduces the chance of missing spam.
These measures still do not work against spam that sends direct POST requests without going through the page.
If spammers attack a Google Form directly, bypassing the website page, you ultimately have to recreate the Google Form itself.
Given those limitations, it is quite effective as a mitigation against certain common bots when implemented with that understanding!
I work mainly on markup and frontend development using JavaScript, React, and Next.js. I'm always happy when a site I've been involved in launches successfully! My hobbies are playing the guitar. I love cats and roasted sweet potatoes 🐱🍠
Hirocchi
Frontend Engineer / Joined in 2022