Disclosure: this article was written with the help of AI and checked by a human against the working theme code. It is posted by the team at AiTech.
A veterinary clinic cannot afford a booking form that says "please enable JavaScript." A client on an old phone, a flaky connection, or a browser that blocked the script still needs to request a visit. Astro is a good fit here, because it ships zero client JavaScript by default. The usual trap is the wizard: once you reach for a UI framework to split the form into steps, the no-JS path disappears.
This article walks through a pattern we use in Fernvale, AiTech's Astro theme for veterinary clinic websites: one native HTML form, three fieldsets, a small progressive-enhancement script, and a POST to a form backend. No React, no islands, no client-side router.
Start with a form that already works
A wizard that only exists in JavaScript has a hard failure mode: a blank page, or a first step with no way to finish. The more resilient version is a normal form that happens to look like a wizard when the script runs.
That means:
- Every field is in the HTML, not rendered later by a component.
- The form has
method="post"and a realaction. - Progress, Next/Back, and hiding later sections are additive.
- Validation uses the platform Constraint Validation API, so the same
requiredandtypeattributes work in both modes — with one caveat, below, aboutnovalidate.
The page is a regular .astro file. The visit-reason dropdown is filled from a content collection, so it stays in sync with the Services pages:
---
import { getCollection } from 'astro:content';
import { site } from '../config/site';
const services = (await getCollection('services')).sort((a, b) => a.data.order - b.data.order);
---
<form
id="booking"
method="post"
action={site.formEndpoint || '#'}
data-endpoint={site.formEndpoint}
>
Each step is a <fieldset> with a <legend> (the accessible name of that group) and a data-step index. Species is a real radio group, labelled by a nearby heading, not a stray placeholder:
<fieldset class="step space-y-6" data-step="0">
<legend class="mb-6 font-display text-3xl">Tell us about your pet</legend>
<div>
<span id="species-label" class="field-label">Species</span>
<div class="flex gap-3" role="radiogroup" aria-labelledby="species-label">
{['Dog', 'Cat'].map((s, i) => (
<label class="flex flex-1 cursor-pointer items-center gap-3 rounded-2xl border-2 px-4 py-3">
<input type="radio" name="species" value={s} required checked={i === 0} />
{s}
</label>
))}
</div>
</div>
</fieldset>
The other two fieldsets follow the same shape: visit reason, preferred date and time, then name, phone, email, and a required consent checkbox that points at the privacy policy. Next and Back are type="button" and start with a hidden class. The submit button is always in the markup. Without JavaScript, a visitor sees the whole form and one "Request appointment" button — which is exactly what we want.
Hide steps only after you know JavaScript will run
If you hide fieldsets 2 and 3 in the CSS by default, a no-JS visitor can never complete the form. If you leave them visible and wait for a deferred module script to hide them, there is a flash of the entire form.
The fix is a one-line inline script in the layout, in the <head>, so the js class lands before the first paint of the body:
<script is:inline>document.documentElement.classList.add('js');</script>
Then a few rules in global CSS:
/* With JS: show only step 1 until the script takes over. */
.js #booking:not([data-ready]) .step:not([data-step="0"]) { display: none; }
.js #booking .steps { display: grid; }
#booking .step[hidden] { display: none; }
If JavaScript never runs, <html> has no js class, every fieldset stays visible, and the progress list (which is hidden in the markup) stays hidden. If JavaScript is about to run, only step 0 is shown until the script sets data-ready and starts using the hidden attribute.
Enhance: per-step checks, then a JSON POST
The enhancement script is a classic Astro <script> — bundled as a deferred module. It reveals the progress list, shows one fieldset at a time, and validates only the current step when the visitor presses Continue:
const validate = (fs: HTMLFieldSetElement) => {
const fields = Array.from(
fs.querySelectorAll<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>(
'input, select, textarea',
),
);
for (const f of fields) {
f.removeAttribute('aria-invalid');
if (!f.checkValidity()) {
f.setAttribute('aria-invalid', 'true');
const label =
form.querySelector(`label[for="${f.id}"]`)?.textContent?.trim() || 'This field';
error.textContent =
f.type === 'checkbox'
? 'Please tick the consent box to continue.'
: f.type === 'email' && f.value
? 'Please enter a valid email address.'
: `${label.replace(/\(.*\)/, '').trim()} is required.`;
error.classList.remove('hidden');
f.focus();
return false;
}
}
return true;
};
checkValidity() reads the same required, type="email", and type="date" attributes the browser would have used. The message goes in a role="alert" region, the failing field gets aria-invalid="true", and focus moves to it. That is enough to stay keyboard- and screen-reader-friendly without a component library.
On submit, the script calls preventDefault only because it is running, then POSTs with fetch and FormData. Asking for JSON stops Formspree and Web3Forms from issuing a full-page redirect:
form.addEventListener('submit', async (e) => {
e.preventDefault();
if (!validate(steps[current])) return;
const endpoint = form.dataset.endpoint;
if (!endpoint) {
// Demo mode: be honest instead of failing silently.
done('Add your form endpoint in src/config/site.ts to receive real requests.');
return;
}
const res = await fetch(endpoint, {
method: 'POST',
body: new FormData(form),
headers: { Accept: 'application/json' },
});
if (!res.ok) throw new Error();
done();
});
On success, hide the form fields, reveal a role="status" region, and focus it (tabindex="-1") so a screen reader announces "Request received." The preferred date also gets min set to today, and a ?reason= query can pre-select the service — both are nice extras, and neither is required for the no-JS path.
Two more accessibility details are worth keeping. The form sits next to a short aside that says, plainly, not to use this form for emergencies and offers a phone number instead. A booking wizard is the wrong place to hide an urgent path. And the custom error region should stay in the DOM (hidden, not removed) so the role="alert" is ready on the first invalid submit. We checked the finished page with axe-core as part of a 27 November 2026 test of the theme (0 WCAG 2.2 AA violations on 16 pages × 2 viewports).
The endpoint itself lives in one config object (site.formEndpoint). Paste a Formspree or Web3Forms URL, redeploy the static site, and the same markup works. Netlify Forms needs a netlify attribute and a form-name field; the FormData POST is otherwise unchanged. The action attribute should be the same URL as data-endpoint, so a no-JS submit goes to the same backend.
A caveat: novalidate belongs in the script, not the markup
To replace the browser's native bubbles with the custom alert, it is tempting to put novalidate on the <form> in the .astro file. That works for the enhanced path — checkValidity() still runs — but it also turns those bubbles off when JavaScript never loads. The form will still POST, yet required fields will not be checked in the browser.
The current Fernvale theme does ship novalidate in the markup. A small improvement, which we have not shipped yet, is to leave novalidate out of the HTML and set it only once the script is in charge:
form.noValidate = true;
Then a no-JS submit still gets the browser's built-in checks, and the enhanced path keeps the custom messages. The form backend should validate either way.
Try it
This pattern is in Fernvale, an Astro and Tailwind theme for veterinary clinics published by AiTech. You can walk through the form on the live demo (the clinic is fictional): fernvale-demo.pages.dev/book.
Top comments (0)