Forms — Goeboek Astro
The three forms of this Astro template work as soon as you run it: the contact form on the Contact page, “Schedule tour” on every property page and the form on the Add property page.
All three check their fields in the browser (the first empty or wrong one gets the focus), show a spinner on the button while sending, then “Thank you” or “Something went wrong”, and drop spam with a hidden honeypot field. On success the contact form clears its fields and stays on the page; “Schedule tour” opens /success-scheduled and Add property opens /success-add-property, as in the original design. On an error every form keeps what the visitor typed.
Out of the box they run in demo mode: nothing is sent, and the fields are logged in the browser console (the tour and Add property forms still open their thank-you pages). That’s fine while you build, but useless once you publish, so pick a destination before launch.
The quickest way to receive messages
Section titled “The quickest way to receive messages”| You want | Mode | Hosting |
|---|---|---|
| An email for every message, tour request and listing, with no server to run | Static: a form service (Formspree, Web3Forms, Getform, Basin) | Any static host |
| Them in a CRM, a spreadsheet, Slack… | 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 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.
All three forms post to the same endpoint; the hidden form field (contact, tour or property) tells them apart,
and subject (“New contact enquiry”, “New tour request”, “New property submission”) becomes the email’s subject at the
services that email you. 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 forms post multipart/form-data and expect a 2xx answer. Details for each service
are in Forms reference.
Server mode
Section titled “Server mode”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, …). -
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_FROMThe senders in a Mailchimp audience FORM_PROVIDER=mailchimp+MAILCHIMP_API_KEY,MAILCHIMP_AUDIENCE_ID;MAILCHIMP_STATUSis optional (below)It in your CRM, Slack, a spreadsheet… FORM_PROVIDER=webhook+FORM_WEBHOOK_URL;FORM_WEBHOOK_SECRETis optionalThe server log only, while you test FORM_PROVIDER=console(the default)Several at once work:
FORM_PROVIDER=resend,mailchimp. The setting applies to all three forms. -
Restart
npm run devand send a test. The forms now post to/api/forms/contact,/api/forms/tourand/api/forms/property(src/lib/forms/route.ts, added bysrc/integrations/forms.ts); every page stays static, only that route runs on the server, and it checks the required fields again. -
Put the same variables in your host’s dashboard before deploying, and redeploy after changing them.
Without an adapter, the build stops with NoAdapterInstalled. Details for each provider, what it receives and how to
write your own provider are in Forms reference.
What the forms send
Section titled “What the forms send”The contact form (form contact, title “New contact enquiry”):
| Field | Name it arrives under | Required |
|---|---|---|
| Name | name |
yes |
email |
yes, and it must look like an e-mail address | |
| Message | message |
no |
“Schedule tour” (form tour, title “New tour request”):
| Field | Name it arrives under | Required |
|---|---|---|
| Property ID (filled in from the property) | propertyId |
yes |
| Property Name (filled in from the property) | propertyName |
yes |
| Name | name |
yes |
email |
yes, and it must look like an e-mail address | |
| Phone | phone |
yes |
| Message | message |
no |
Add property (form property, title “New property submission”), in the order of the page:
| Group | Fields (name it arrives under) | Required |
|---|---|---|
| Personal Information | name, email, phone |
all |
| Property Description | propertyName; location and category (radio buttons: Brooklyn, Manhattan, Queens, Staten Island, The Bronx; Apartments, Condos, Houses, Villas); for (Sell or Rent); price (a number); duration (/Days, /Months or /Years) |
propertyName, for, price, duration |
| Property Details | size (m2), bedrooms, bathrooms, floor, additionalSpace, furnishing, ceilingHeight (m), constructionYear, renovation (dates as YYYY-MM-DD) |
all but renovation |
| Property Utility | heating, airCondition, fireplace, elevator, ventilation, intercom, windowType, cableTv, wifi (Yes / No, or text for heating and window type) |
none |
| Message | message |
no |
A field left empty arrives as "" (a radio group nobody picked, a select left on “Select…”). In server mode, Resend sends
the title followed by the sender’s name as the email’s subject (“New tour request — Jane Smith”), lists every filled field
as “Label: value” and sets the reply address to the one typed in the form; Mailchimp adds or updates the sender in your
audience (name → FNAME, phone → PHONE), tags them with the title and keeps the submission as a note; a webhook
receives { form, title, submittedAt, data, labels } as JSON.
Mailchimp and consent
Section titled “Mailchimp and consent”MAILCHIMP_STATUS decides what you may send to the people the forms add: transactional (the default) stores the
contact but they can’t receive your campaigns, pending sends them a confirmation e-mail first (double opt-in), and
subscribed is only for addresses that gave explicit consent. None of the three forms asks for marketing consent, so
keep transactional unless you add a consent checkbox. To change which fields fill the audience’s merge fields, edit
mergeFields in src/lib/forms/providers/mailchimp.ts (field names are matched ignoring case).
Changing the forms
Section titled “Changing the forms”The words and fields are in the page copy:
- the contact form:
forminsrc/content/pages/contact.json(its title, thename,emailandmessagefields, the button’s three texts and thenotificationtitle); - “Schedule tour”:
tourinsrc/content/pages/property.json(the title, the text, the six fields, the button’s texts,redirect:/success-scheduled, and thenotificationtitle); - Add property:
forminsrc/content/pages/add-property.json(the five groups and their fields, the button’s texts,redirect:/success-add-property, and thenotificationtitle).
Each field has a name (what you receive), a label (what people read above it, and what the notifications show), a
placeholder, a type (text, email, tel, number, date; radio with options for Location and Category; a
field with options alone is a select) and required. The browser and the server route read the same flags
(src/lib/forms/definitions.ts), so a field you make optional or required there is checked that way. Change redirect
to send a form to another page once sent; remove it to stay on the page with “Thank you” on the button.
A new field goes in the copy, then into the form’s section (src/components/sections/ContactDetails.astro,
TourForm.astro or AddPropertyForm.astro) and into its list in src/lib/forms/definitions.ts, so it is placed and
delivered. The form itself is src/design-system/components/forms/Form.astro, and its script
src/design-system/scripts/form.ts. Keep a field named email in every form: Resend and Mailchimp use it.
Testing before launch
Section titled “Testing before launch”- Send each of the three forms from your own site after deploying, with a real address.
- Check the destination (inbox, spreadsheet, audience), and that the tour request names its property.
- 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 button says “Something went wrong” and the form still holds what was typed.
The honeypot stops the usual bots: each 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).
Privacy
Section titled “Privacy”Messages, tour requests and listings go only where you point them; nothing is sent anywhere else. The forms collect names, e-mail addresses, phone numbers and details of people’s property: say what happens to them in your privacy policy, and choose a form service or provider that keeps the data where the law where you work allows. The template has no privacy page and no consent checkbox: add them if your visitors’ country requires it (Pages and sections).