2024-05-22 · Astro
Handle form submissions with Astro Actions
Build a validated contact form that works without JavaScript and upgrades gracefully when it loads.
Introduction
A step-by-step guide to defining server actions, validating input with Zod, and wiring a plain HTML form to them. You get progressive enhancement for free instead of rebuilding your form inside a client framework.
Field notes
A few patterns we kept seeing while puttering around Astro problems:
- The simple version survived every refactor; the clever version didn’t.
- Documentation written during the work aged far better than documentation written after.
- The second time a problem shows up, it is already a pattern — name it.
A checklist you can steal
- The failure is reproducible with one command.
- The fix has a test that fails without it.
- Someone other than the author has run it on their machine.
Closing
Write the short version future-you will actually read. That is the whole trick.