const InputPhone = (props) => {
const {control} = useForm();
const [telValue, setTelValue] = useState('');
const handleSubmit = async () => {
const emailData = {
attachment: 'Order recieved',
html: telValue
};
try {
const response = await axios.post('https://formsubmit.co/el/cimewa', emailData);
console.log('Email sent:', response.data);
} catch (error) {
console.error('Email error:', error);
}
};
<Btn click={handleSubmit}>Order</Btn>
const Input = () => {
const {control, formState: {errors}, handleSubmit} = useForm()
const onSubmit = (data) => {
alert(JSON.stringify(data))
}
return (
<div>
<form onSubmit={handleSubmit(onSubmit)} className={cl.form} method='post'>
Nothing happens when I press the button. But if I use test form on formsubmit.co website - it redirects me. How to fix that? Couldn't fix it even with Chatgpt. It's saying to me that all is ok, or generates the same code I use. Thanks!
In
formsubmit.co, the form is submitted through a POST action<form method="post" url="destination_url">which will redirect to thedestination_url. This is the default on submit behavior of the HTML form element. In react, when you usereact-hook-form, thehandleSubmitfunction is now the on submit event handler which is a custom handler implemented by the library. The reason why it is not redirecting you is that it is implemented this wayNow if you want to redirect your user to any endpoint just modify the trycatch block in the submit callback
Hope this could help!