All guides

Astro guide

Astro contact form, no server or adapter

Static Astro sites have no server to receive a form. You don't need an SSR adapter or an API endpoint: a plain HTML form posting to Formcrate works with zero client JavaScript.

  1. 1Create a form and copy its key

    Sign up with Google, create a form and enter the email address that should receive submissions. Copy the form key from the dashboard: it replaces YOUR_FORM_KEY below. The free plan includes 500 submissions a month.

  2. 2Add your form key

    Variables prefixed PUBLIC_ can be used in components.

    .env
    PUBLIC_FORMCRATE_KEY=YOUR_FORM_KEY
  3. 3Create the component

    This is plain HTML, so it works without any JavaScript. Visitors land on a confirmation page, or on your own page if you set redirectTo.

    src/components/ContactForm.astro
    ---
    const endpoint = `https://www.formcrate.dev/api/submit/${import.meta.env.PUBLIC_FORMCRATE_KEY}`;
    ---
    
    <form action={endpoint} method="POST">
      <input type="text" name="name" placeholder="Name" required />
      <input type="email" name="email" placeholder="Email" required />
      <textarea name="message" placeholder="Message" required></textarea>
      <input type="text" name="_gotcha" style="display:none" tabindex="-1" autocomplete="off" />
      <input type="hidden" name="redirectTo" value={new URL('/thanks', Astro.site ?? Astro.url).href} />
      <button type="submit">Send</button>
    </form>
  4. 4Use it on a page

    Create src/pages/thanks.astro too if you kept the redirectTo field.

    src/pages/contact.astro
    ---
    import ContactForm from '../components/ContactForm.astro';
    ---
    
    <h1>Contact</h1>
    <ContactForm />
  5. 5Send a test submission

    Fill in the form on your site and submit it. The message appears in your Formcrate inbox and arrives by email within a few seconds. Anything that looks like spam goes to the Spam tab instead and isn't emailed.

  6. 6Lock the form to your domain

    Your key is visible in the page source, which is normal for form backends. In the form settings, add your domain under Domain lock so other websites can't post to your form from the browser.

Tips

  • Want to stay on the page? Add a <script> that sends new FormData(form) with fetch and Accept: application/json, like the React guide.
  • Set site in astro.config.mjs so the redirect URL uses your real domain.

Get your Astro form working

Free for 500 submissions a month. Spam filtering, email alerts and an inbox included. No card required.

Create a free form

Guides for other stacks