Forms — Marai Neesu Astro
The two forms of this Astro template work as soon as you run it: the inquiry on the Contact page and the newsletter sign-up on the Blog page.
Each form checks the required fields, shows a spinner while sending, says “Thank you” and clears the fields, 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 both 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 |
|---|---|---|
| An email for every submission, with no server to run | Static: a form service (Formspree, Web3Forms, Getform, Basin) | Any static host |
| Submissions in your CRM, Slack, a spreadsheet, a mailing list… | 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.
The endpoint is public (it is in the page), which is how these services are designed to work; they filter spam on
their side. Both forms post to the same endpoint, with form (contact or newsletter) and subject (the submission’s
title) next to the fields. Details for each service are in Forms reference.
A form service emails you each sign-up of the newsletter as well; to collect the addresses in a mailing list, send the forms to a webhook (Zapier, Make, n8n) that adds them to your list, or use Mailchimp in server mode.
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_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 from each form. The forms now post to/api/forms/contactand/api/forms/newsletter(src/lib/forms/route.ts, added bysrc/integrations/forms.ts); every page stays static, only that route runs on the server. -
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”The inquiry on the Contact page (form contact, button “Send message”, title “New contact inquiry”):
| Field | Name it arrives under | Required |
|---|---|---|
| First Name | firstName |
yes |
| Last Name | lastName |
yes |
email |
yes | |
| Phone Number | phone |
yes |
| I’m interested in … (a checkbox for each service: Product Design, Web Design, Mobile App Design, User Experience (UX) Design) | interests (a list of the ticked ones) |
|
| Project Budget (USD) | budget |
yes |
| Message | message |
The newsletter on the Blog page (form newsletter, button “Subscribe”, title “New newsletter subscriber”): email
(Email, required).
A form service or webhook in static mode receives the title as subject, and one interests value for each ticked box.
In server mode, Resend puts the sender’s name after the title in the email’s subject (“New contact inquiry — Jane
Smith”) and sets the reply address to the sender’s e-mail; Mailchimp stores the first and last name as FNAME and
LNAME, tags the contact with the title and the services they ticked, and keeps the rest as a note; 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, the placeholders, the button’s three texts (“Send message”, “Thank you” and “Something went wrong” for the
inquiry; “Subscribe” and the same two for the newsletter) and the title of each submission (notification) are
content: contactForm in src/content/pages/contact.json and newsletter.form in src/content/pages/blog.json. A
field arrives at your service under its name, so keep the names you already map somewhere. The choices of “I’m
interested in” are not typed there: they are the titles of your services (src/content/collections/services.json), so
they follow when you add, rename or remove a service.
Each form sends every field it shows, and in server mode src/lib/forms/definitions.ts reads the same lists to check
the required ones again, so the list in the copy is the place to edit:
- To make a field required, or optional, set
"required": trueon it, or delete that line. The label stays as it is (the design marks no field as required), but the browser checks it before sending and, in server mode, the route checks it again. A required field must be on the page: in server mode, a required field that is only in the list makes every submission fail. - To add a field to the inquiry, for example a website:
-
add an entry to
contactForm.fieldsincontact.json(mind the comma between entries):"website": { "name": "website", "label": "Website", "placeholder": "https://", "type": "url", "autoComplete": "url" }The types are
text(the default),email,tel,urlandtextarea; -
hand it to the section in
src/pages/contact.astro:website: toField(fields.website),infields; -
place it in
src/components/sections/ContactSection.astro: add"website"to the names in thefieldstype ofProps, and<FormField {...fields.website} />where it should show.
-
- To remove a field, delete its entry and its lines in the same two files.
- The newsletter’s one field is laid out in
src/components/sections/NewsletterSection.astro, inside its pill. - 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, with a real address: one inquiry and one sign-up.
- 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: the inquiry collects a name, an e-mail, a phone number and a budget, the newsletter an e-mail. The template has no privacy page and no consent checkbox; add a page of your own (Pages and sections) and link it from the footer.
The inquiry doesn’t ask for marketing consent, so if you send it to Mailchimp, keep MAILCHIMP_STATUS at
transactional (the default): those contacts can get your replies, not your campaigns. The newsletter is a sign-up, so
its contacts get Mailchimp’s confirmation e-mail first (MAILCHIMP_NEWSLETTER_STATUS=pending, the default) and join
your campaigns once they confirm.