Forms — Fitbricks Astro
The forms of this Astro template work as soon as you run it: the contact form, the free-trial form and the booking form of every club.
The contact form (“Get in Touch”) is on Contact, the free-trial form (“Claim Free Trial”) on Free trial, and the booking form (“Book Your Class Now”) in the sidebar of every club page, filled in with that club’s name. Each form checks the required fields, shows a spinner while sending, says “Thank you” and clears the fields (the booking form goes back to its club), keeps what the visitor typed when something fails (“Something went wrong”), and drops spam with a hidden honeypot field.
Out of the box they 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. One destination serves all three forms; every submission says which form it came from, so you can tell them apart in your inbox or tool.
The quickest way to receive submissions
Section titled “The quickest way to receive submissions”| You want | Mode | Hosting |
|---|---|---|
| Messages and sign-ups by email or in your CRM, with no server to run | Static: a form service (Formspree, Web3Forms, Getform, Basin) or a webhook (Zapier, Make, n8n, Pipedream) that passes them on to Google Sheets, Slack, a CRM… | Any static host |
| Mailchimp or Resend 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 each form. -
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. All three forms post to the same endpoint, with form (contact, free-trial or booking) and subject
(“Get in Touch”, “Claim Free Trial”, “Book Your Class Now”) next to the fields. Details for each service are in
Forms reference.
Server mode
Section titled “Server mode”For Mailchimp or Resend 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, …). -
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_FROM(replying answers the visitor)Members and leads in a Mailchimp audience FORM_PROVIDER=mailchimp+MAILCHIMP_API_KEY,MAILCHIMP_AUDIENCE_ID;MAILCHIMP_STATUS(consent)It in your CRM, Slack, a spreadsheet… FORM_PROVIDER=webhook+FORM_WEBHOOK_URL(Zapier, Make, n8n, Formspree, your own API);FORM_WEBHOOK_SECRETis optionalThe server log only, while you test FORM_PROVIDER=console(the default)Several at once work:
FORM_PROVIDER=resend,mailchimp. -
Put the variables in your host’s dashboard and deploy. The forms post to
/api/forms/contact,/api/forms/free-trialand/api/forms/booking; every page stays static.
Without an adapter the build stops with NoAdapterInstalled. What each provider receives, the webhook payload,
Mailchimp’s merge fields and how to write your own provider (HubSpot, Brevo, Airtable…) are in
Forms reference.
What the forms ask for
Section titled “What the forms ask for”A field arrives under its name, shown here before its label. The e-mail is required on every form, so each provider
has an address to reply to or add (the original design required only the contact time). “Contact Time Preferences”
stays required: its drop-down starts on “Anytime”, a prompt the visitor can’t submit, so they pick Morning, Afternoon,
Evening or Night.
Contact (form: contact, button “Submit”):
| Field | Name it arrives under | Required |
|---|---|---|
| Name | Name |
|
Email |
yes | |
| Phone | Phone |
|
| Contact Time Preferences | Contact Time |
yes |
| Message | Message |
Free trial (form: free-trial, button “Submit”): the same fields, plus two groups of choices before the message:
| Field | Name it arrives under | Choices |
|---|---|---|
| Preferred Location | City |
Every city of cities.json |
| Preferred Class | Class |
The first ten programs of programs.json (count in the copy) |
Booking on every club page (form: booking, button “Book Now”):
| Field | Name it arrives under | |
|---|---|---|
| Name | Name |
|
| Phone | Phone |
|
Email |
Required | |
| Club Location | Club |
Filled in with the club’s name |
| Preferred Date | Date |
A date picker |
| Preferred Time | Time |
A time picker |
| Additional Notes | Message |
An e-mail that doesn’t look like an address shows the browser’s error without sending.
Changing the forms
Section titled “Changing the forms”The fields, labels, placeholders, the button’s three texts and the title of each submission are content:
| Form | Copy | Layout |
|---|---|---|
| Contact | form in src/content/pages/contact.json |
src/components/sections/contact/ContactMainSection.astro |
| Free trial | form in src/content/pages/free-trial.json |
src/components/sections/free-trial/FreeTrialSection.astro |
| Booking | booking in src/content/pages/club.json |
src/components/sections/club/ClubMainSection.astro |
A field arrives at your service under its name, so keep the names you already map somewhere.
-
To make a field required, set
"required": trueon it. The browser checks required fields before sending, and server mode checks them again (src/lib/forms/definitions.ts). KeepEmailrequired if you deliver to Mailchimp: it refuses a submission without an address. -
To add a field, add an entry to the form’s
fields; the form draws every entry in order. For example a goal:{ "name": "Goal", "label": "Your goal", "type": "text", "placeholder": "Lose weight, build strength…", "required": false }The types are
text,email,tel,date,time,textareaandselect(withoptions, the first being the prompt). Free trial lays its form out in three parts: the text, e-mail, phone and drop-down fields first, then the two choice groups, then onetextarea, the message (a secondtextareais not shown). -
To remove a field, delete its entry.
-
To change the classes offered on Free trial, change
countof theClassfield (the first programs ofprograms.json), or the order of the programs. -
Don’t give a real field the name
fax: it is the honeypot’s (Spam).
Testing before launch
Section titled “Testing before launch”- Submit each form on your own site after deploying, with a real address: a contact message, a free-trial request and a booking from one club page.
- Check the destination (inbox, audience, spreadsheet) and reply to the test message.
- Try a failure on purpose: a wrong endpoint or API key, 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. Form services filter spam on their side too. If you start getting
spam anyway, turn on the service’s captcha, or make more fields required.
Privacy and consent
Section titled “Privacy and consent”Submissions go only where you point them; nothing is sent anywhere else, and the site itself stores nothing. The forms carry no consent line. The legal pages are samples written for the demo gym: have your Privacy Policy say how you handle the names, e-mails, phone numbers and messages people send you — and which form service receives them — before you collect any (Editing the content).
Mailchimp adds new contacts as transactional unless you set MAILCHIMP_STATUS: they can get your replies, not your
campaigns. To send them marketing emails you need their consent: set pending (Mailchimp emails a confirmation link first:
double opt-in, the safest choice) or subscribed (only if your form asks for marketing consent where you publish). In
server mode the provider applies to all three forms; each contact is tagged with the form it came from.