Forms — Cerette Astro
The inquiry forms of this Astro template work as soon as you run it: Name, Email, Phone, Location, Project type, Project budget and Project details, on Contact, Services and every service page.
They check the required fields (Project type and Project budget), show a spinner on the button while sending, say “Thank you” and clear the fields, keep what the visitor typed when something fails (“Something went wrong”), and drop spam with a hidden honeypot field.
There are two forms with the same fields:
| Form | Where | Sent as | Title of each submission |
|---|---|---|---|
contactForm |
Contact and Services | contact |
“New inquiry from the Cerette website” |
serviceForm |
Every service page | service |
“New service inquiry from the Cerette website” |
On a service page, Project type is a text field that starts with the service’s name (“Architecture”); on Contact and Services it is a list of choices.
Three modes
Section titled “Three modes”Out of the box the forms run 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. You choose the mode with environment variables, with no code changes:
| Mode | Set | Hosting | Where submissions go |
|---|---|---|---|
| Demo (the default) | nothing | Any static host | Nowhere: the form shows “Thank you” and logs the fields in the browser console |
| Static | PUBLIC_FORM_ENDPOINT |
Any static host | Posted from the browser to a form service (Formspree, Web3Forms, Getform, Basin) or a webhook (Zapier, Make, n8n, Pipedream) |
| Server | PUBLIC_FORM_MODE=server + FORM_PROVIDER |
A host with an Astro adapter | Delivered by the site’s own route to the server log, a webhook, Mailchimp or Resend |
Most sites want static mode: it keeps the site 100% static and takes two minutes. Every mode shows the same button states and drops the same spam.
Static mode: a form service or webhook
Section titled “Static mode: a form service or webhook”-
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 and from a service 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.
Both forms post to the same endpoint. Each submission carries every field by its name, plus form (contact or
service) and subject (the form’s title), so you can tell them apart. The endpoint is public (it is in the page),
which is how these services are designed to work; they filter spam on their side. Details for each service are in
Forms reference.
Server mode: the site’s own route
Section titled “Server mode: the site’s own route”For Resend or Mailchimp without a third-party service, the forms post to a route on your own site:
-
Add the adapter for your host:
npx astro add vercel(ornetlify,node, …). Without one the build stops withNoAdapterInstalled. -
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 forms now post to/api/forms/contactand/api/forms/service(src/lib/forms/route.ts, added bysrc/integrations/forms.ts); every page stays static, only that route runs on the server. The route checks the required fields again and accepts posts from your own pages only. -
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 forms ask for
Section titled “What the forms ask for”| Field | Kind | Name it arrives under | Required |
|---|---|---|---|
| Name | text | name |
|
email |
|||
| Phone | phone | phone |
|
| Location | text | location |
|
| Project type | a list: Architecture, Construction, Interior, Planning, Renovation, Landscape (on a service page, a text field with the service’s name) | type |
yes on Contact and Services |
| Project budget | a list: Under $50K … $500K+ | budget |
yes |
| Project details | a text area | details |
Each field shows its label above it and a placeholder inside (“Enter your full name”); the lists start on their placeholder, which the visitor must replace. As in the original design, only the two lists are required: a visitor can send a form without a name or an e-mail address. If you want them, mark them required (below).
A form service or webhook in static mode receives every field by its name and the title as subject. In server mode,
Resend puts the sender’s name after the title in the email’s subject and sets the reply address to the sender’s e-mail;
Mailchimp stores the name as FNAME, tags the contact with the title and keeps the rest as a note (it needs an e-mail: a form sent without one shows “Something went wrong”, so make Email
required if you use Mailchimp);
a webhook receives every field of the form, as "" when left empty, with its label.
Changing the forms
Section titled “Changing the forms”The labels, placeholders, choices, the button’s three texts (“Send Inquiry”, “Thank you” and “Something went wrong”)
and the title of each submission (notification) are content: contactForm and serviceForm in
src/content/pages/forms.json. A field arrives at your service under its name, so keep the names you already map
somewhere. Write your own notifications: the demo’s name Cerette. In server mode src/lib/forms/definitions.ts reads
the same lists to check the required fields again, so the copy is the place to edit:
-
To change the choices of Project type or Project budget, edit their
options(Project budget is in both forms). -
To make a field required or optional, set or remove
"required": trueon it, in both forms. The browser checks it before sending and, in server mode, the route checks it again. -
To add a field, add an entry to both forms (mind the comma between entries), for example a company:
"company": { "name": "company", "label": "Company", "placeholder": "Enter your company", "autoComplete": "organization" }The types are
text(the default),email,tel,url,select(withoptions; the placeholder is its empty first choice) andtextarea. The fields are laid out by hand, so also place it insrc/components/sections/InquiryForm.astro: add its name to the list of field names, take it fromspec.fieldswith the others (const { name, email, …, company } = …) and add<FormField {...company} />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 in both forms, its name in that list and its
<FormField … />line. Keepnameandemail: Resend and Mailchimp use them. -
Don’t give a real field the name
fax: it is the honeypot’s (Spam).
Testing before launch
Section titled “Testing before launch”- Submit both forms on your own site after deploying (Contact and a service page), 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: every 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. Most countries expect you to say what happens
to the data people send you, and the forms collect a name, an e-mail address, a phone number, a location, a budget and a
message. The template’s Privacy Policy (src/content/collections/legal.json) is a sample: replace it with your own,
written for your business and the law where you work.
The forms don’t ask for marketing consent, so if you send them to Mailchimp, keep MAILCHIMP_STATUS at transactional
(the default): those contacts can get your replies, not your campaigns.