Skip to content
Wrenform

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

  1. Create a form (free) and copy its form ID.
  2. Save the snippet as src/components/ContactForm.astro and replace YOUR_FORM_ID.
  3. Import it into a page and render <ContactForm />.
  4. 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 netlify or data-netlify attribute, so it leaves this form alone and the browser posts it to Wrenform. Add your netlify.app address 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.dev address and your custom domain to Allowed origins. If you set a Content-Security-Policy header, add form-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?
No. The form posts from the visitor's browser to Wrenform, so your site can stay fully static.
Can I use it in a React, Svelte or Vue island?
Yes. Any component that posts with fetch works. The Next.js guide's React component runs in an Astro island with client:load.
Where do I keep the form ID?
In the component, or in an environment variable that starts with PUBLIC_. The ID is public by design, so either is fine.
Does it work with astro dev?
Yes. Leave allowed origins empty while you test, or add http://localhost:4321.

Next steps