Lead Capture Form
What it does
Writes the code for a short contact or signup form, with proper labels, clear error messages and a confirmation once it’s sent. It asks for as little as possible and works with a phone, a keyboard or a screen reader.
When to use it
- You need a contact, callback or email signup form on a page
- Your current form has no labels, looks bad on phones or is hard to use with a screen reader
- You want the HTML right before you connect it to a backend
The prompt
Act as a front-end developer who builds accessible forms. Rules: Every input has a real <label> (not just a placeholder). Use correct input types and autocomplete attributes. Mark required fields accurately. Validation messages are announced to assistive tech. The form works and looks right on a phone. Ask for the minimum fields the goal needs, with no data-harvesting beyond that.
What the form is for: [CONTACT / CALLBACK / EMAIL SIGNUP / OTHER]
The absolute minimum fields the goal needs: [LIST. Challenge me if I list more than necessary]
Where it submits: [an endpoint / mailto / "just the markup for now"]
My CSS variables (if any): [PASTE or "none"]
Give me:
1. The semantic HTML form: labelled fields, correct types, autocomplete, required flags, and an accessible submit button.
2. Inline validation: HTML-native where possible, with clear, polite error text and an aria-live region for messages.
3. The success state: what the user sees after submitting, handled accessibly (focus moves to the confirmation).
4. CSS using my variables, comfortable tap targets, no layout shift when errors appear.
5. A one-line note on where to add spam protection (honeypot / provider-side) without adding a captcha unless it's needed.
Example
This is a made-up case, and we asked the AI to keep its answer short.
What we filled in:
What the form is for: CALLBACK. People who are locked out or want a lock changed leave their number and I ring them back. The absolute minimum fields the goal needs: name, mobile number, what the job is in one line, best time to call. I was going to add email and street address too but I don't think I need them before I call. Where it submits: an endpoint, POST to /api/callback on my site, which answers 200 with a small JSON body when it worked My CSS variables (if any): --brand: #1b4332, --brand-dark: #0f2a1f, --ink: #1a1a1a, --paper: #ffffff, --error: #b3261e, --radius: 8px, --space: 16px, --font: system-ui
What came back:
1. The semantic HTML form
You're right to leave out email and street address. You don't need them to ring someone back.
<form class="cb" id="cb-form" action="/api/callback" method="post">
<p>All fields are required.</p>
<label for="cb-name">Your name</label>
<input id="cb-name" name="name" type="text" autocomplete="name" required aria-describedby="cb-name-err"><p class="err" id="cb-name-err"></p>
<label for="cb-tel">Mobile number</label>
<input id="cb-tel" name="mobile" type="tel" autocomplete="tel" pattern="[0-9 +\-\(\)]{7,20}" required aria-describedby="cb-tel-err"><p class="err" id="cb-tel-err"></p>
<label for="cb-job">What is the job? One line is fine.</label>
<input id="cb-job" name="job" type="text" maxlength="120" autocomplete="off" required aria-describedby="cb-job-err"><p class="err" id="cb-job-err"></p>
<label for="cb-time">Best time to call</label>
<select id="cb-time" name="best_time" required><option>As soon as possible</option><option>Morning</option><option>Afternoon</option><option>Evening</option></select>
<p class="live" id="cb-live" aria-live="polite"></p>
<button type="submit">Ask for a callback</button>
</form>
2. Inline validation
The rules sit in the HTML, so the browser's own checks still work if the script fails to load. The script swaps the browser pop-ups for a polite message under each field and reads it out through the live region.
<script>
const form = document.getElementById("cb-form"), live = document.getElementById("cb-live"); form.noValidate = true;
const msgs = { "cb-name": "Please enter your name.", "cb-tel": "Please enter a mobile number.", "cb-job": "Please say what the job is." };
function check(el) {
const err = document.getElementById(el.id + "-err");
if (err === null) return true;
const ok = el.checkValidity();
el.setAttribute("aria-invalid", ok ? "false" : "true");
err.textContent = live.textContent = ok ? "" : msgs[el.id];
return ok;
}
form.addEventListener("focusout", e => { if (e.target.value) check(e.target); });
form.addEventListener("input", e => { if (e.target.getAttribute("aria-invalid") === "true") check(e.target); });
</script>
3. The success state
On a 200 the form hides and focus moves to the thank-you, so a screen reader reads it straight away. If sending fails, what they typed stays and the problem is read out.
<div class="cb" id="cb-done" tabindex="-1" hidden>
<h2>Thanks, your request is in.</h2>
<p>I will ring you back on the number you gave.</p>
</div>
<script>
let sending = false;
form.addEventListener("submit", async e => {
e.preventDefault();
const bad = [...form.elements].filter(el => check(el) === false);
if (bad.length) { live.textContent = bad.length + (bad.length > 1 ? " fields need" : " field needs") + " checking."; bad[0].focus(); return; }
if (sending) return;
sending = true; live.textContent = "Sending...";
try {
const res = await fetch(form.action, { method: "POST", body: new URLSearchParams(new FormData(form)) });
if (res.ok === false) throw new Error(res.status);
const done = document.getElementById("cb-done"); form.hidden = true; done.hidden = false; done.focus();
} catch (err) { live.textContent = "Sorry, that did not send. Please try again."; }
sending = false;
});
</script>
4. CSS using your variables
Fields and the button are 48px tall. Each message line keeps its space while empty, so nothing jumps when an error appears.
<style>
.cb { max-width: 32rem; margin: 0 auto; padding: var(--space); font-family: var(--font); color: var(--ink); background: var(--paper); }
.cb label { display: block; margin-top: var(--space); font-weight: 600; }
.cb input, .cb select { box-sizing: border-box; width: 100%; min-height: 48px; margin-top: 4px; padding: 8px 12px; font: inherit; color: var(--ink); background: var(--paper); border: 2px solid var(--ink); border-radius: var(--radius); }
.cb [aria-invalid="true"] { border-color: var(--error); }
.cb .err { min-height: 1.5em; margin: 4px 0 0; color: var(--error); }
.cb .live { min-height: 3em; margin: var(--space) 0 0; }
.cb button { width: 100%; min-height: 48px; border: 0; border-radius: var(--radius); background: var(--brand); color: var(--paper); font: inherit; font-weight: 600; cursor: pointer; }
.cb button:hover { background: var(--brand-dark); }
.cb :focus-visible { outline: 3px solid var(--brand-dark); outline-offset: 2px; }
</style>
5. Spam protection
Add a hidden honeypot field and check it, along with any rate limiting, in your /api/callback handler on the server, or turn on your host's spam filter, and only add a captcha if spam still gets through.
Tips
- Keep the fields to a minimum. Let it talk you down to a name and one other field where that’s enough.
- Paste your CSS variables so the form matches the rest of your site.
- Afterwards, ask for the code that sends the form in your setup, such as Netlify Forms, Formspree or your own API route.
- Test it with only the keyboard. Tab through, submit, and check that you can read the error messages.