Multiple submit buttons to different api endpoints #8814
-
Hi, I am quite new into hook form. Haven't found any solutions for my problem though. As far as I have come there seems to be no submit at all if I don't provide an "onSubmit" property to the main form element. I have multiple forms using the same template and therefore I have to provide the submission URL's (one for saving and one for sending) dynamically for each form. I guess my basic question is how I should structure a form with two submit-buttons. Can anyone please help out? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
In general, for multiple different submit actions you'd call const { handleSubmit } = useForm()
return (
<section>
<button onClick={handleSubmit(onSaveAsDraft)}>Save as Draft</button>
<button onClick={handleSubmit(onSubmit)}>Submit</button>
</section>
) |
Beta Was this translation helpful? Give feedback.
In general, for multiple different submit actions you'd call
handleSubmit
onClick
of different buttons passing differentonSubmit
callbacks to each of them.