Skip to content
Sign inJoin waitlist

Forms — Brickfolio Astro

The two forms of this Astro template work as soon as you run it: the contact form on Home (“Let’s Connect”) and the newsletter box in the footer of every page.

Both 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 fields are cleared; on an error the contact 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. That’s fine while you build, but useless once you publish, so pick a destination before launch.

You want Mode Hosting
An email for every message and sign-up, with no server to run Static: a form service (Formspree, Web3Forms, Getform, Basin) Any static host
Messages in a CRM, a spreadsheet, Slack, your mailing tool… 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.

  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.

Both forms post to the same endpoint; the hidden form field (contact or newsletter) tells them apart, and subject (“New message from the contact form”, “New newsletter subscriber”) 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.

For Resend or Mailchimp 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 message and sign-up FORM_PROVIDER=resend + RESEND_API_KEY, FORM_EMAIL_TO, FORM_EMAIL_FROM
    The senders in a Mailchimp audience FORM_PROVIDER=mailchimp + MAILCHIMP_API_KEY, MAILCHIMP_AUDIENCE_ID; MAILCHIMP_STATUS is optional (below)
    It in your mailing tool, Slack, a spreadsheet… FORM_PROVIDER=webhook + FORM_WEBHOOK_URL; 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. The setting applies to both forms.

  3. Restart npm run dev and send a test. The forms now post to /api/forms/contact and /api/forms/newsletter (src/lib/forms/route.ts, added by src/integrations/forms.ts); every page stays static, only that route runs on the server, and it checks the fields again.

  4. 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, the webhook payload and how to write your own provider are in Forms reference.

The contact form (form contact, title “New message from the contact form”):

Field Name it arrives under Required
First name First Name yes
Last name Last Name yes
E-mail Email yes, and it must look like an e-mail address
Phone number Phone Number yes
Message Message no

The newsletter box (form newsletter, title “New newsletter subscriber”):

Field Name it arrives under Required
E-mail (placeholder “Enter your email”) Email yes, and it must look like an e-mail address

In server mode, Resend sends the title as the email’s subject, lists every filled field and sets the reply address to the one typed in the form; Mailchimp adds or updates the sender in your audience, tags them with the title and keeps the submission as a note; a webhook receives { form, title, submittedAt, data, labels } as JSON.

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. For the newsletter box, pending is the usual choice.

The contact form goes to the same audience when Mailchimp is on. Its name fields are kept in the note; to fill the audience’s first and last name, add them to mergeFields in src/lib/forms/providers/mailchimp.ts ("first name": "FNAME", "last name": "LNAME"; field names are matched ignoring case).

The contact form’s words and fields are contact in src/content/pages/home.json: the title and text, the fields (each with its name, label, placeholder, type — text, email, tel or textarea — and required), the button’s label (submit, “Send message”) and its two messages (success, error). The browser and the server route read the same list (src/lib/forms/definitions.ts), so a field you add, remove or make optional there is checked and sent that way. The first two fields sit side by side from 810 px (src/components/sections/Contact.astro).

The newsletter box’s words are footer.newsletter in src/content/site.json:

Field Demo
title “Subscribe to Our Newsletter”
text “Join now and never miss out on our stuff again. Because you are worth it!”
placeholder “Enter your email” (also the field’s name for screen readers)
submit “Subscribe”
success “Thank you”
error “Something went wrong”

The box is src/design-system/components/forms/NewsletterForm.astro and its script src/design-system/scripts/newsletter.ts; the contact form’s script is scripts/form.ts. Keep a field named Email: Resend and Mailchimp use it.

  • Send the contact form and sign up from your own site after deploying, with a real address.
  • Check the destination (inbox, spreadsheet, audience).
  • Try a failure on purpose: point PUBLIC_FORM_ENDPOINT at 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 contact 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), or a provider with double opt-in (MAILCHIMP_STATUS=pending).

Messages and sign-ups go only where you point them; nothing is sent anywhere else. The forms collect names, e-mail addresses and phone numbers: 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).