Docs unclear on how to handle forms for static sites #10878
Replies: 3 comments 2 replies
-
Just reposting my comment from discord regarding this
|
Beta Was this translation helpful? Give feedback.
-
Also pointing out from the Discord discussion that there are in fact many ways to "do forms" in Astro (which is why we already have multiple recipes!), so it can admittedly get a bit complicated. 😅 Will note there's already a related open issue that we've discussed and added the help wanted label at #10374 . |
Beta Was this translation helpful? Give feedback.
-
To answer the question a bit more generally: for static sites you generally can’t handle form submissions. They are a folder full of HTML files with no way to receive and do stuff with forms on the server. Instead there are a few alternative approaches people tend to use:
Long story short: you do need some kind of server that knows how to process user data, but there are several approaches and what you choose can depend a bit on your circumstances. |
Beta Was this translation helpful? Give feedback.
-
I'm going through the gauntlet of learning astro by building my own site, and I had a good time going through the basics and getting a static site up and running. I was able to integrate a component library and everything, had a few pages, routing, etc. was great.
But when it came time to add a form and call an api, I got lost real quick. The first page I found was the build-forms recipe. And that indicated that the project needed to be SSR'd for forms to work in Astro. So I went through those steps begrudgingly, because I didn't feel like I should set my whole project to
output: 'server'
to handle a form.Then the very next recipe had an example with a front-end framework, which I also didn't want to use just to do a form.
Then I looked at api endpoints, and just got confused real quick.
I already have an issue open for this, but I think it warrants a larger discussion on how to do some simple form stuff quickly in Astro.
My suggestion would be to have another section of the docs (maybe in the recipes) that are dedicated to interactivity on static sites.
Beta Was this translation helpful? Give feedback.
All reactions