How to Handle Astro and HTMX Forms Without a Server
Keeping an Astro site purely static is fast and cheap until you need a contact form, beta waitlist, or bug report box. Here is how to wire Astro and HTMX forms to a hosted endpoint without turning on SSR adapters.
Why static Astro builds break down at the contact form
Astro shines when you ship plain HTML to a CDN edge with zero runtime servers. The moment you add an /api/contact route inside Astro, you have to configure a server adapter, manage SMTP or Resend API keys, build rate limiting, and defend the endpoint against spam bots.
Offloading submission handling to an external HTML form mailer keeps your build output completely static while giving you server-side validation, archiving, and email routing out of the box.
Pattern 1: Zero-JavaScript Astro component
For most marketing pages, a plain HTML form inside an .astro component is the cleanest approach. It works even if a visitor disables JavaScript and adds zero kilobytes to your client bundle.
---
const endpoint = "https://formspool.com/f/YOUR_FORM_ID";
---
<form action={endpoint} method="POST" class="contact-form">
<label>
Email
<input type="email" name="email" required />
</label>
<label>
Project Details
<textarea name="message" rows="4" required></textarea>
</label>
<input type="text" name="_gotcha" style="display:none" tabindex="-1" autocomplete="off" />
<input type="hidden" name="_next" value="https://yoursite.com/thanks" />
<button type="submit">Send Inquiry</button>
</form>Pattern 2: Inline feedback in Astro or HTMX apps
When you want inline confirmation without leaving the current page, pair your form with AJAX form submission and inspect the JSON response from FormsPool. If a required field fails validation, the server returns HTTP 422 with exact field error codes so you can highlight the input directly.
| Setup Option | Client JS Added | Server Adapter Needed | Built-in Spam Archive |
|---|---|---|---|
| Plain HTML POST to FormsPool | 0 KB | No | Yes (Inbox + Spam tabs) |
| Fetch JSON to FormsPool | < 1 KB inline script | No | Yes (with HTTP 422 errors) |
| Custom Astro API Route + SMTP | ~1 KB | Yes (Node / Edge) | Must build yourself |
Pattern 3: HTMX submission with inline status swap
HTMX lets you keep HTML as the source of truth while avoiding full-page reloads. Combine hx-post with hx-headers so FormsPool returns JSON, then handle the htmx:afterRequest event to show a clean confirmation message or highlight validation errors.
<form
hx-post="https://formspool.com/f/YOUR_FORM_ID"
hx-headers='{"Accept": "application/json"}'
hx-swap="none"
hx-on::after-request="if(event.detail.successful){ this.reset(); document.querySelector('#status').textContent='Message sent!'; }"
>
<input type="email" name="email" required />
<textarea name="message" required></textarea>
<input type="text" name="_gotcha" style="display:none" tabindex="-1" />
<button type="submit">Send</button>
<p id="status" role="status"></p>
</form>Common Astro View Transitions gotcha
If your Astro site enables <ClientRouter /> (View Transitions), a plain DOMContentLoaded listener only fires on the initial hard load and silently stops attaching to forms after client-side navigation.
Bind your AJAX submit handler inside document.addEventListener("astro:page-load", initForm) instead. Plain HTML method="POST" forms do not suffer from this issue because they require zero client-side listeners.
Deploying on Cloudflare Pages, Netlify, and GitHub Pages
Because FormsPool runs externally over HTTPS with permissive CORS headers for public submission endpoints, the exact same build output works identically across GitHub Pages, Cloudflare Pages, Netlify, and S3 + CloudFront. You never have to rewrite form handlers when moving static hosts.
Preventing bot floods on static sites
Static sites are easy targets because the form action URL is visible in HTML source. Always pair the hidden _gotcha input with FormsPool's form spam protection and configure server-side length limits on the message field inside the Workflow tab.
If you are migrating an existing static site from another provider, our Formspree migration guide shows how to swap endpoints without changing your markup.
Frequently Asked Questions
Do Astro static builds need an SSR adapter to process contact forms?
No. When your form posts to a hosted FormsPool endpoint, your Astro site stays 100% static on Cloudflare Pages, Netlify, or GitHub Pages with zero serverless functions.
Can HTMX submit directly to a FormsPool endpoint?
Yes. Standard HTML form posts work with zero client JavaScript, or you can send an AJAX fetch request with Accept: application/json and swap the confirmation state inline.