Form not submitting in Nextjs14
Answered
Sun bear posted this in #help-forum
Sun bearOP
I made a form with tsx, zod, tailwindcss and react-hook-form. However, I am unable to submit the form. I'm not getting errors on the client or server consoles so I assume it's a zod validation error.
The form is huge so I'm providing the repo: https://github.com/aidanmcintosh07/spice-inn-form
Location: Location of the form in the folder: https://i.stack.imgur.com/9TfEl.png
I tried changing around the zod schema, displaying the form errors for the fields manually and fixing them within the form, removing the loading state on the onSubmit function.
The form is huge so I'm providing the repo: https://github.com/aidanmcintosh07/spice-inn-form
Location: Location of the form in the folder: https://i.stack.imgur.com/9TfEl.png
I tried changing around the zod schema, displaying the form errors for the fields manually and fixing them within the form, removing the loading state on the onSubmit function.
Answered by aardani
so there you go, form is not submitting because of client-side error, therefore its a validation error :D
27 Replies
@Sun bear I made a form with tsx, zod, tailwindcss and react-hook-form. However, I am unable to submit the form. I'm not getting errors on the client or server consoles so I assume it's a zod validation error.
The form is huge so I'm providing the repo: https://github.com/aidanmcintosh07/spice-inn-form
Location: Location of the form in the folder: https://i.stack.imgur.com/9TfEl.png
I tried changing around the zod schema, displaying the form errors for the fields manually and fixing them within the form, removing the loading state on the onSubmit function.
You should be able to checkk the error mesasge from the return of the
useForm hooks from react-hook-formthen you can check what the client-side error message is
Sun bearOP
how do i implement that? I haven't used
useForm outside of how it's configured with zod.Sun bearOP
thanks
lmk if it works
Sun bearOP
np
im trying to combine this line
with my ```const form = useForm<z.infer<typeof formSchema>>({ ...// })
const {
register,
formState: { errors },
handleSubmit,
} = useForm()with my ```const form = useForm<z.infer<typeof formSchema>>({ ...// })
Sun bearOP
ohhh ok
lemme try that
so from what i see, it should push an error (if there is one) to the form.formState.errors object whenever i interact with the inputs of my form right?
No, if the zod validation failes, the error is already populated in the errors object
its part of the
handleSubmit() methodSun bearOP
alright
So in this case, you could see if its a client-side error, by printing the error of the form first
and if indeed its a client-side error, you can implement a User friendly UI to display the error, like Toast or Dialog or Error Messages
Sun bearOP
ok here are the errors
Nice!
Sun bearOP
perfect
so there you go, form is not submitting because of client-side error, therefore its a validation error :D
Answer
Sun bearOP
thought so but i just had no idea which inputs were causing it lol
thanks so much man
@Sun bear thought so but i just had no idea which inputs were causing it lol
Yes, i recommend skimming the basics of react-hook-form though, jsut to get the gist of how it works haha