Forms — Metuo Astro
The booking form of this Astro template works as soon as you run it: “Tell us about you.”, on Home, Services and Contact.
It checks the e-mail (the only required field) and shows “Please enter a valid email address.” under it when it is
missing or wrong, shows a spinner on its Submit button while sending, says “Thank you” and clears the fields, keeps what
the visitor typed when something fails (“Something went wrong”), and drops spam with a hidden honeypot field. The three
places are the same form (book) and send to the same destination.
Out of the box it runs in demo mode: nothing is sent, and the fields are logged in the browser console. That’s fine while you build, but useless once you publish, so pick a destination before launch.
The quickest way to receive submissions
Section titled “The quickest way to receive submissions”| You want | Mode | Hosting |
|---|---|---|
| An email for every booking request, with no server to run | Static: a form service (Formspree, Web3Forms, Getform, Basin) | Any static host |
| Requests in your CRM, calendar tool, Slack, a spreadsheet… | Static: a webhook (Zapier, Make, n8n, Pipedream) | Any static host |
| Resend or Mailchimp directly, with no third party in between | Server: the site’s own route (below) | A host with an Astro adapter |
Most sites want static mode: it keeps the site 100% static and takes two minutes.
-
Create a form at your service and copy its endpoint URL (Formspree:
https://formspree.io/f/<id>). -
Copy the example settings and paste the URL:
Terminal window cp .env.example .envPUBLIC_FORM_ENDPOINT=https://formspree.io/f/abcdwxyzWeb3Forms also needs
PUBLIC_FORM_ACCESS_KEY. -
Restart
npm run devand send a test from the Contact page. -
If your host builds the site, put the same variable in its dashboard before deploying:
.envstays on your computer (it is not in Git). The value is written into the pages when the site builds, so rebuild after changing it.
The endpoint is public (it is in the page), which is how these services are designed to work; they filter spam on
their side. The form posts its fields with form (book) and subject (the submission’s title, “New session request”)
next to them. Details for each service are in Forms reference.
Server mode
Section titled “Server mode”For Resend or Mailchimp without a third-party service, the form posts to a route on your own site:
-
Add the adapter for your host:
npx astro add vercel(ornetlify,node, …). -
Set
PUBLIC_FORM_MODE=server, and choose where submissions go withFORM_PROVIDER:You want Set An email for every submission FORM_PROVIDER=resend+RESEND_API_KEY,FORM_EMAIL_TO,FORM_EMAIL_FROMIt in your CRM, Slack, a spreadsheet… FORM_PROVIDER=webhook+FORM_WEBHOOK_URL(Zapier, Make, n8n, Formspree, your own API);FORM_WEBHOOK_SECRETis optionalThe sender in a Mailchimp audience FORM_PROVIDER=mailchimp+MAILCHIMP_API_KEY,MAILCHIMP_AUDIENCE_IDThe server log only, while you test FORM_PROVIDER=console(the default)Several at once work:
FORM_PROVIDER=resend,mailchimp. -
Restart
npm run devand send a test. The form now posts to/api/forms/book(src/lib/forms/route.ts, added bysrc/integrations/forms.ts); every page stays static, only that route runs on the server. -
Put the same variables in your host’s dashboard before deploying, and redeploy after changing them.
Details for each provider, what it receives, the webhook payload, Mailchimp consent settings and how to write your own provider are in Forms reference.
What the form asks for
Section titled “What the form asks for”The booking form (form book, button “Submit”, title “New session request”):
| Field | Name it arrives under | Required |
|---|---|---|
| First Name | first-name |
|
| Last Name | last-name |
|
email |
yes | |
| Phone | phone |
|
| Preferred session type (a checkbox per service) | service, once for each ticked box |
|
| Preferred Date | date (YYYY-MM-DD) |
|
| Preferred Time | time (HH:MM, 24-hour) |
|
| What would you like support with? | message |
Each field has its label above it and a placeholder inside (“Jane”, “jane@example.com”…). The session types are the
names of the services in src/content/collections/services.json: add, rename or remove a service and the checkboxes
follow. In server mode, Resend puts the sender’s first and last name after the title in the email’s subject (“New session
request — Jane Smith”) and sets the reply address to the sender’s e-mail; Mailchimp stores the names as FNAME and
LNAME, tags the contact with the title and keeps the rest as a note; a webhook receives every field of the form (""
when left empty, service as a list) with its label.
Changing the form
Section titled “Changing the form”The labels, placeholders, the e-mail’s error message, the button’s three texts (“Submit”, “Thank you” and “Something went
wrong”), the title of the form card (“Tell us about you.”, formTitle) and the title of each submission
(notification) are content: form in src/content/pages/book.json. A field arrives at your service under its name,
so keep the names you already map somewhere.
The form sends every field it shows, and in server mode src/lib/forms/definitions.ts reads the same list to check the
required ones again, so the list in the copy is the place to edit:
-
To make a field required, set
"required": trueon it and give it anerrormessage (to require the phone number, for example). The browser checks it before sending and, in server mode, the route checks it again. No asterisk is shown: say it in the label if you want to. A required field must be on the page: in server mode, a required field that is only in the list makes every submission fail. -
To add a field, add an entry (mind the comma between entries), for example a preferred contact method:
"contactBy": { "name": "contact-by", "label": "How should we reach you?", "type": "checkboxes", "options": ["Email", "Phone"] }The types are
text(the default),email,tel,date,time,textareaandcheckboxes(withoptions). The fields are laid out by hand, so also place it in the form, insrc/components/sections/BookSection.astro: add<FormField {...fields.contactBy} />where it should go (withclass="md:col-span-2"for a full-width one; the fields sit two by two from tablets up). -
To remove a field, delete its entry and its
<FormField … />line. Keepemail: Resend and Mailchimp use it. -
Don’t give a real field the name
fax: it is the honeypot’s (Spam).
Testing before launch
Section titled “Testing before launch”- Submit the form on your own site after deploying, with a real address.
- Check the destination (inbox, spreadsheet, audience) and reply to the test.
- Try a failure on purpose: point
PUBLIC_FORM_ENDPOINTat a wrong URL in a test build (or set a wrong API key in server mode), submit, and confirm the visitor sees “Something went wrong” and their text is still there.
The honeypot stops the usual bots: the form carries a hidden field named fax that a person never sees; a bot that
fills it is shown “Thank you” and nothing is sent. If you start getting spam anyway, use a form service in static mode
(Formspree, Web3Forms and Basin all include spam filtering), or add a captcha to the form component
(src/design-system/components/forms/Form.astro).
Privacy
Section titled “Privacy”Submissions go only where you point them; nothing is sent anywhere else. A booking request can say a lot about a person:
their name, e-mail and phone, and in the message what they would like support with, which may touch on their health. Most
countries expect you to say what happens to that data, and some ask for more care with health information. The demo’s
Privacy Policy (/legal/privacy-policy) is a sample with placeholders: replace it with your own
(Editing the content), and choose a form service or provider that keeps the data where the law where you
work allows. Metuo has no consent checkbox: add one (a checkboxes field, as above) if you need it.
The form doesn’t ask for marketing consent, so if you send it to Mailchimp, keep MAILCHIMP_STATUS at transactional
(the default): those contacts can get your replies, not your campaigns.