All guides

Contact form for Astro

Astro builds static HTML by default, so there's no server to receive a form post unless you add an adapter. With Pasteform, a plain <form> in an .astro component works on any host, and a few lines of client script make it submit without a reload.

Get my free form link Replace YOUR_FORM_ID below with your form ID, or copy the snippets from your dashboard where it's already filled in.

Step by step

  1. Create a form in Pasteform and copy the endpoint.
  2. Create src/components/ContactForm.astro with the code below.
  3. Use it on a page: import ContactForm from "../components/ContactForm.astro"; then <ContactForm />.
  4. Build and deploy as usual (output: "static" is fine). Add your domain, and localhost for astro dev, to Allowed domains.

src/components/ContactForm.astro

---
const endpoint = "https://forms.prizenlabs.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="_gotcha" style="display:none" tabindex="-1" autocomplete="off">
  <button type="submit">Send</button>
</form>

<script>
  // Optional: submit without leaving the page.
  document.querySelectorAll('form[action="https://forms.prizenlabs.com/f/YOUR_FORM_ID"]').forEach((form) => {
    form.addEventListener("submit", async (e) => {
      e.preventDefault();
      const button = form.querySelector('button[type="submit"]');
      button.disabled = true;
      try {
        const res = await fetch(form.action, {
          method: "POST",
          headers: { Accept: "application/json" },
          body: new FormData(form),
        });
        const data = await res.json();
        if (!res.ok || !data.success) throw new Error(data.message);
        form.innerHTML = "<p>Thanks! We'll be in touch soon.</p>";
      } catch (err) {
        alert(err.message || "Sorry, something went wrong. Please try again.");
        button.disabled = false;
      }
    });
  });
</script>

Allowed domains

Add your production domain and localhost (for astro dev).

Common pitfalls

What you get

Make your Astro form send

Free form link in about 2 minutes. No credit card.

Get my free form link

Guides for other platforms

Lovable · Bolt · v0 · Framer · Webflow · Next.js · Hugo · Jekyll · GitHub Pages · Netlify · Vercel · WordPress (static export) · Carrd · plain HTML