SolidStart render page from POST function

I have a form in SolidStart with method="post" and action="". To validate the form on server side, I export a POST function. However I am wondering how I could, if the data I got isn't valid, show the form again with the data the user already submitted (and maybe additional error messages) from this POST function?
9 Replies
apollo79
apollo79OP3y ago
So I think the basic question here is how to render a page from a POST function
Jérémy
Jérémy3y ago
Did you check this page in the doc? https://start.solidjs.com/core-concepts/actions
SolidStart Beta Docuentation
SolidStart Beta Documentation
Early release documentation and resources for SolidStart Beta
apollo79
apollo79OP3y ago
Yep, I read it.
apollo79
apollo79OP3y ago
GitHub
How to properly handle errors in form? · Discussion #548 · solidjs/...
Hi, I'd like to handle field errors when submitting a form using createServerAction$. I understand I can throw a ResponseError but I can't find in the doc how to use it. The ultimat...
Jérémy
Jérémy3y ago
Oh ok, I don't know if you know about https://felte.dev/ but, I ended up using it for my project, which is heavy on forms. What I basically did was create a component for each field ; they take as props errors, data, setFields , setErrors, etc from Felte's Form helper. That way I can update the UI according my Zod validation rules, at the UI level. Then on the server (using a API route), I submit the form and I re-use my form Zod Schema (which is composed of field-level schema) to validate the form globally, and process the values.
Felte | Home
An extensible form library for Svelte, Solid and React.
Jérémy
Jérémy3y ago
Maybe that's not really crystal clear, but I really found Felte to intuitive. And I ended up with complex forms quite easily.
apollo79
apollo79OP3y ago
Sounds good to me basically, but it lacks no-js support, I think?
Jérémy
Jérémy3y ago
Yeah, that's right. In my context, this is not an issue.
apollo79
apollo79OP3y ago
👍 Yes, I'd like my site to work good without JS enabled, so I have to search a solution...
Want results from more Discord servers?
Add your server