Sub topic 5
Building the Sign-up Form in HTML
This chapter assumes you know basic HTML tags and attributes, and that you know an email service provider (ESP) stores your subscribers. You do not need a framework. A sign-up form is a plain HTML form element that sends data to a server.
How a form works
When a visitor presses the submit button, the browser checks each field against its rules. If every field passes, the browser sends the field values to the URL in action, using the HTTP method in method. Your ESP, or your own server, receives the values and adds the address to the list.
A complete form
<form action="https://example.com/subscribe" method="post">
<label for="email">Email address</label>
<input type="email" id="email" name="email" autocomplete="email" required>
<div style="position:absolute;left:-9999px" aria-hidden="true">
<label for="website">Leave this field empty</label>
<input type="text" id="website" name="website" tabindex="-1" autocomplete="off">
</div>
<label>
<input type="checkbox" name="consent" value="yes" required>
I agree to receive the weekly newsletter and can unsubscribe at any time.
</label>
<button type="submit">Subscribe</button>
</form>What each part does
actionandmethod="post": where the data goes and how it is sent. Use POST so addresses do not appear in URLs or server logs as query strings.type="email": the browser rejects values that are not shaped like an address. On phones it also shows a keyboard with the@key.required: blocks submission of an empty field.name: the key the server receives. A field without anameis not submitted at all.label formatchingid: ties the text to the input. Clicking the label focuses the field, and screen readers announce it.autocomplete="email": lets the browser fill the address in one tap.- The consent checkbox: it is unticked and
required, so the visitor must make an active choice. The consent chapter covers the legal wording. - The hidden
websitefield: a honeypot, which is a field that people never see but bots often fill in. The server should reject any submission where it has a value. The spam chapter explains this in detail.
Common errors
| Mistake | Effect | Fix |
|---|---|---|
| Missing `name` on the input | The server receives nothing for that field | Give every submitted field a `name` |
| Placeholder used instead of a label | The hint disappears while typing and is unreliable for screen readers | Keep a visible `label` |
| `type="text"` for the address | No built-in validation, wrong mobile keyboard | Use `type="email"` |
| Relying only on browser checks | Anyone can bypass them by posting directly | Validate again on the server |
| Pre-ticked consent box | Consent is not a clear, active choice | Leave the box unticked |
| Using `display:none` on a honeypot | Some bots skip hidden fields | Move it off-screen as shown |
Testing the form
Open the page and submit an empty form. The browser should block it and name the field. Then type abc into the email field and confirm the browser objects. Finally, submit a valid address and check that your ESP shows it with the consent value recorded. Use your keyboard only (Tab, Space, Enter) to confirm the whole form works without a mouse.
Exercise
A teammate's form shows a labelled email field and a Subscribe button. Submissions arrive at the server, but the email value is always missing. What is the most likely cause, and how do you fix it?
Show answer
The email input most likely has no name attribute. Browsers only submit fields that have a name, so the value is dropped. Add name="email" (or whatever key the ESP expects) to the input.