Zephos Formsby Zephos

Guide · Astro

Add a contact form to an Astro site

Astro sites are usually static, so there is no server to receive a form. Drop this component in and the form posts to Zephos Forms, with or without JavaScript.

  1. Create a free account and a form. Copy its access key.

  2. Create src/components/ContactForm.astro. It works without client-side JavaScript.

    ---
    // src/components/ContactForm.astro
    const endpoint = "https://forms.zephos.dev/submit";
    const accessKey = "YOUR_ACCESS_KEY";
    const redirect = new URL("/thanks", Astro.site ?? Astro.url).href;
    ---
    <form action={endpoint} method="POST">
      <input type="hidden" name="access_key" value={accessKey} />
      <input type="hidden" name="_redirect" value={redirect} />
      <label>Name <input name="name" required /></label>
      <label>Email <input name="email" type="email" required /></label>
      <label>Message <textarea name="message" required></textarea></label>
      <input type="text" name="_gotcha" tabindex="-1" autocomplete="off"
             style="position:absolute;left:-5000px" aria-hidden="true" />
      <button type="submit">Send</button>
    </form>
  3. Use it on any page: import ContactForm from "../components/ContactForm.astro"; then <ContactForm />. Set site in astro.config.mjs so the redirect URL is absolute.

  4. Submit the form once from your live site. The submission shows up in your dashboard and in your inbox.

Good to know

Other guides: Plain HTML · Lovable