I want to have two submit buttons for my form.
Both will use the same inputs and form validation, but will do different tasks
export default function Formtwosubmits() {
function handlesubmit_task1(){
}
function handlesubmit_task2(){
}
return (
<>
<form onSubmit={handlesubmit_task1 if task 1 button pressed || handlesubmit_task2 if task2 button pressed } >
<Button variant="contained" color="primary" type="submit">
task 1
</Button>
<Button variant="contained" color="primary" type="submit">
task 2
</Button>
.... here input fields
</form>
</>
);
}
I am not able to undertand how to pass different handlesumit functions for different buttons
I have tried:
export default function Formtwosubmits() {
function handlesubmit_task1(){
}
function handlesubmit_task2(){
}
return (
<>
<form >
<Button variant="contained" color="primary" type="submit" onClick={handlesubmit_task1}>
task 1
</Button>
<Button variant="contained" color="primary" type="submit" onClick={handlesubmit_task2}>
task 2
</Button>
.... here input fields
</form>
</>
);
}
putting onClick on the button. with type=submit but this does not check the form validation (like required etc), whereas with onSubmit i see the form validation is checked
How can i trigger form validation with onClick. even that can help me