Forms and Email Sign-ups: Honeypots, Consent and Conversion
Collect enquiries and sign-ups safely: see how a form handler checks required fields, consent and a hidden honeypot field, test it with valid and invalid submissions against a real endpoint, and compute a conversion rate with its uncertainty.
In this lesson you will
- Explain what happens when a form is submitted
- Validate fields and require consent
- Use a honeypot against spam
- Measure the conversion rate with uncertainty
About 28 minutes
The newsletter box
Priya wants a box on every page where visitors can leave their email address to hear about new scents. In a no-code builder, you drag a form block into the page, choose the fields and say where submissions go, and the builder handles the rest, often by sending each entry to your inbox or to a list in an email service. Behind the block, a form is an HTTP POST request from the visitor’s browser to an address, a form endpoint, carrying the field values. The endpoint checks them, stores them, and answers with a success or an error page. Understanding that makes it easier to test, to choose a service and to see what can go wrong.
Three things deserve care. First, validation: the endpoint must check that required fields are present and that the email looks like an email, because browsers can be bypassed. Second, consent: privacy laws, such as the European GDPR, generally require clear, unticked, informed agreement before you add someone to a marketing list, and a record of when it was given. Laws differ by country and change, so check the rules that apply to you. Third, spam: bots fill every form they find. A honeypot is a simple defence: an extra field hidden from humans with styling, such as a field called “website”. People never see it and so leave it empty, and bots fill every field, so a submission with a value in it is thrown away. CAPTCHA services and rate limits add more protection, and a double opt-in, an email with a confirmation link, makes sure that the address belongs to the person who typed it.
| Check | Why | Result for a bad case |
|---|---|---|
| Email looks valid | Typos and fake entries | 400 |
| Consent ticked | Privacy law | 400 |
| Honeypot empty | Bots fill every field | Silently discard (200) |
| Already subscribed | Avoid duplicates | 200, no second entry |
| Rate limit per address | Stop floods | 429 |
import json, threading, re, urllib.request, urllib.error, urllib.parse
from http.server import BaseHTTPRequestHandler, HTTPServer
subscribers, discarded, rejected = {}, [], []
EMAIL = re.compile(r"^[^@\s]+@[^@\s]+\.[^@\s]+$")
class FormEndpoint(BaseHTTPRequestHandler):
def do_POST(self):
form = urllib.parse.parse_qs(self.rfile.read(int(self.headers["Content-Length"])).decode())
get = lambda k: (form.get(k, [""])[0]).strip()
email = get("email").lower()
if get("website"): # the honeypot: humans leave it empty
discarded.append(email); return self.reply(200, "thanks") # do not tell the bot
if not EMAIL.match(email): rejected.append(("bad email", email)); return self.reply(400, "please enter a valid email")
if get("consent") != "yes": rejected.append(("no consent", email)); return self.reply(400, "please tick the consent box")
if email in subscribers: return self.reply(200, "you are already on the list")
subscribers[email] = {"consent": "yes", "source": get("page") or "unknown", "n": len(subscribers) + 1}
self.reply(200, "welcome")
def reply(self, code, text):
b = text.encode(); self.send_response(code); self.send_header("Content-Length", str(len(b))); self.end_headers(); self.wfile.write(b)
def log_message(self, *a): pass
srv = HTTPServer(("127.0.0.1", 0), FormEndpoint); url = "http://127.0.0.1:%d/subscribe" % srv.server_address[1]
threading.Thread(target=srv.serve_forever, daemon=True).start()
def submit(**fields):
req = urllib.request.Request(url, data=urllib.parse.urlencode(fields).encode())
try: r = urllib.request.urlopen(req); return r.status, r.read().decode()
except urllib.error.HTTPError as e: return e.code, e.read().decode()
tests = [("valid sign-up", dict(email="Ada@Example.com", consent="yes", page="home")), ("same address again", dict(email="ada@example.com", consent="yes")),
("missing consent", dict(email="bo@example.com")), ("not an email", dict(email="bo-at-example", consent="yes")),
("bot fills the honeypot", dict(email="bot@spam.example", consent="yes", website="http://spam.example")), ("second valid sign-up", dict(email="chen@example.com", consent="yes", page="candles"))]
rows = []
for label, f in tests:
code, text = submit(**f); rows.append([label, code, text]); print(label.ljust(26), code, text)
print("stored subscribers:", sorted(subscribers), "| discarded as spam:", discarded, "| rejected:", [r[0] for r in rejected])
print("DATA " + json.dumps({"rows": rows, "subs": sorted(subscribers), "discarded": discarded, "rejected": [r[0] for r in rejected], "port": srv.server_address[1]}))
srv.shutdown()
valid sign-up 200 welcome
same address again 200 you are already on the list
missing consent 400 please tick the consent box
not an email 400 please enter a valid email
bot fills the honeypot 200 thanks
second valid sign-up 200 welcome
stored subscribers: ['ada@example.com', 'chen@example.com'] | discarded as spam: ['bot@spam.example'] | rejected: ['no consent', 'bad email']
Six submissions went to a real endpoint on a local port, and each shows a rule. The first valid sign-up was stored, with the address lower-cased so that “Ada@Example.com” and “ada@example.com” are the same person, together with the proof of consent and the page that it came from. The same address a second time got a friendly “already on the list” and no second entry. A submission without the consent box ticked was refused with 400 and the message to tick it, and an entry without a valid-looking email address was refused too. The bot that filled in the hidden “website” field got a cheerful 200 “thanks”, so that it does not learn that it was caught, and its address was never stored. At the end the list holds exactly 2 subscribers: ada@example.com, chen@example.com.
Independent check: a second, minimal endpoint with the same rules, tested with curl, gave 200 for a valid sign-up, 400 for a missing consent box, and 200 for the honeypot case with nothing stored for it, and its list contains only the valid address. The state of the first endpoint, its list of subscribers, its discard list and its rejections, was read directly from its own memory and agrees with the replies that the client received. If a form service that you choose offers these features, such as honeypots, consent fields and double opt-in, check its documentation and test it in the same way, with a few good and bad entries.
A form is also something to measure. Suppose that over a month 1,840 visitors saw the sign-up box and 57 subscribed (invented numbers). The conversion rate is 57/1,840 = 3.10 percent, and the 95 percent confidence interval, from the Wilson formula, is 2.40 to 3.99 percent. If Priya changes the headline and the next month gives 71 sign-ups from 1,790 visitors, 3.97 percent, the intervals of the two months overlap, so the difference may well be chance. Counting more visitors, as the Web design course explained for A/B tests, is the only way to be sure.
Check by hand: 57 divided by 1,840 is 0.0310, 3.10 percent. The honeypot case returned 200 on purpose, so the count of accepted replies, 4 of 6 requests, is not the count of subscribers, 2. The two rejections were for consent and for the address, and one request was a duplicate.
Pre-ticked boxes and vague wording do not count as consent in many places. Record when and how each person agreed, offer an easy way to unsubscribe, and check the law where your customers live.
Send a confirmation link and add the address only when it is clicked. It prevents typos and sign-ups by other people, and keeps your list healthy and your messages out of the spam folder.
Builders, plans and prices change often, so the lessons use generic labels such as Builder A and describe categories of tools, and you must check each vendor’s current website for features, prices and limits. Every calculation and check in this lesson was run while the course was written, in Python 3.13 or Node.js 22, on sample data that the lesson provides, with a second independent calculation. This is not legal advice. Privacy and marketing rules differ between countries and change, so check the rules that apply to you and your customers.
Practice
Add a rate limit of three submissions per address per hour. Add a double opt-in step that marks an address as confirmed. Compute the conversion rate and confidence interval for your own form after a month.
Check what you learned
Five quick questions. Pick an answer and you will see straight away whether it is right and why.
What does a form submission send?
- An email
- A text message
- A cookie only
- An HTTP POST with the field values
The endpoint decides what to do.
What is a honeypot field?
- A password field
- A payment field
- A hidden field that only bots fill in
- A file upload
Humans leave it empty.
Why store proof of consent?
- It speeds up the form
- Browsers need it
- Privacy law often requires it
- It prevents spam
Who, when and how.
Why answer 200 to a bot that fills the honeypot?
- Because it is valid
- So that it does not learn it was caught
- To store its address
- It is required by HTTP
Do not train the bots.
What is double opt-in?
- Two forms
- A confirmation link that the person must click
- Two passwords
- A payment step
Proves that the address belongs to them.
Summary
- A form is an HTTP POST to an endpoint that validates and stores the data.
- Check emails, require consent and use a honeypot against bots.
- Double opt-in keeps lists clean.
- Measure conversion with an interval, and respect privacy law.
Questions
Which email service should I connect?
One that handles consent, unsubscribes and deliverability, and offers a free tier to start. Compare current plans and terms, and check that it stores data where your privacy rules require.
Do I need a CAPTCHA?
Not always. A honeypot and rate limits stop many bots, and a CAPTCHA adds friction for real people. Use one if spam becomes a problem.
What is a good conversion rate?
It depends enormously on the offer and the traffic. Measure your own and try to improve it step by step, rather than comparing with other sites.
