Skip to content
Sign inJoin waitlist

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.

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.

  1. Create a form at your service and copy its endpoint URL (Formspree: https://formspree.io/f/<id>).

  2. Copy the example settings and paste the URL:

    Terminal window
    cp .env.example .env
    PUBLIC_FORM_ENDPOINT=https://formspree.io/f/abcdwxyz

    Web3Forms also needs PUBLIC_FORM_ACCESS_KEY.

  3. Restart npm run dev and send a test from each form.

  4. If your host builds the site, put the same variable in its dashboard before deploying: .env stays 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.

For Mailchimp or Resend without a third-party service, the forms post to a route on your own site:

  1. Add the adapter for your host: npx astro add vercel (or netlify, node, …).

  2. Set PUBLIC_FORM_MODE=server, and choose where submissions go with FORM_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_SECRET is optional
    The server log only, while you test FORM_PROVIDER=console (the default)

    Several at once work: FORM_PROVIDER=resend,mailchimp.

  3. Put the variables in your host’s dashboard and deploy. The forms post to /api/forms/contact, /api/forms/free-trial and /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.

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 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 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.

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": true on it. The browser checks required fields before sending, and server mode checks them again (src/lib/forms/definitions.ts). Keep Email required 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, textarea and select (with options, 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 one textarea, the message (a second textarea is not shown).

  • To remove a field, delete its entry.

  • To change the classes offered on Free trial, change count of the Class field (the first programs of programs.json), or the order of the programs.

  • Don’t give a real field the name fax: it is the honeypot’s (Spam).

  • 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.

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.