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.
Create a free account and a form. Copy its access key.
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>Use it on any page:
import ContactForm from "../components/ContactForm.astro";then<ContactForm />. Setsiteinastro.config.mjsso the redirect URL is absolute.Submit the form once from your live site. The submission shows up in your dashboard and in your inbox.
Good to know
- On the free plan, visitors see a short thank-you page with a link back to your site. Paid plans send them to your own page (
_redirect). - Fields starting with an underscore are settings, not data:
_redirect,_subject,_replyto,_gotcha. - JSON requests get JSON back:
{ "success": true, "id": "sub_..." }.
Other guides: Plain HTML · Lovable