Contact forms / Astro
Contact form for Astro without a backend
A static Astro component that emails you every submission. No adapter, no API endpoint.
Why Astro needs a form backend
Astro builds static HTML by default. To handle a form yourself, you would switch on server output, add an adapter for your host, write an API endpoint, and wire up an email service and spam checks.
With Wrenform the component stays static. The form posts to your Wrenform endpoint; we store the submission, filter spam and email you. Your Astro project keeps output: "static" and deploys anywhere.
The snippet
Replace YOUR_FORM_ID with the ID of your form.
---
// src/components/ContactForm.astro
const endpoint = "https://wrenform.com/f/YOUR_FORM_ID";
---
<form action={endpoint} method="POST">
<label>Name <input type="text" name="name" required /></label>
<label>Email <input type="email" name="email" required /></label>
<label>Message <textarea name="message" required></textarea></label>
<input type="text" name="_honey" style="display:none" tabindex="-1" autocomplete="off" />
<button type="submit">Send</button>
</form>Steps
- Create a form (free) and copy its form ID.
- Save the snippet as
src/components/ContactForm.astroand replaceYOUR_FORM_ID. - Import it into a page and render
<ContactForm />. - Build, deploy, and add your site to Allowed origins.
Spam handling
Spam filtering is on for every form, with no CAPTCHA: a hidden honeypot field, a timing check, rate limits per visitor, and a content score for links, keywords and gibberish. Spam goes to a separate tab and is never emailed. See how spam filtering works.
Want to stay on the page? Astro bundles a <script> in the component, so a few lines of fetch can show the result inline while the form still works without JavaScript. The guide has the code.
Deployment notes
- Netlify. Deploy as usual. Netlify only processes forms that carry its own
netlifyordata-netlifyattribute, so it leaves this form alone and the browser posts it to Wrenform. Add yournetlify.appaddress and your custom domain to Allowed origins. - Vercel. Nothing to configure. The Astro build stays static; you don't need a serverless function for the form. Add your production domain to Allowed origins. Preview deployments get their own addresses, so leave the list empty while you test them, or add each one.
- Cloudflare Pages. No Pages Function needed. Add your
pages.devaddress and your custom domain to Allowed origins. If you set a Content-Security-Policy header, addform-action https://wrenform.com. - GitHub Pages. GitHub Pages serves static files only, which is all this form needs. Add
https://<user>.github.io(or your custom domain) to Allowed origins. The origin is the host only, without the repository path.
FAQ
Do I need an Astro adapter for a contact form?
Can I use it in a React, Svelte or Vue island?
Where do I keep the form ID?
Does it work with astro dev?
Next steps
- The full Astro guide: every option, testing, and common problems.
- Contact form for Next.js without an API route
- Contact form for Hugo without a server
- Pricing: free for 250 submissions a month.