That’s the solution i used, but does nothing good, i get the generic success page html in response.data
just to confirm this, i am trying this in a react app
here is the form onSubmit handler
const handleVerify = async (e) => {
e.preventDefault();
try {
setSendingOtp(true);
const response = await axios.post(
"/",
encode({
"form-name": "contact",
countrycode: values.countrycode,
mobilenumber: values.mobilenumber,
}),
{
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Accept: "application/json",
},
},
);
if (response.status === 200) {
sessionStorage.setItem("code", response.data);
restart(getTwoMinutesTime());
setVerificationTextField(true);
setShowOtpTimer(true);
setOtp({ code: "", error: "", success: false });
setSendingOtp(false);
toast.success(
"Verification code has been sent to your given mobile number",
);
}
} catch (error) {
setSendingOtp(false);
toast.error(error?.response?.data || error.message);
}
};
the static html inside index.html:
<form name="contact" netlify netlify-honeypot="bot-field" hidden>
<input type="text" name="countrycode" />
<input type="text" name="mobilenumber" />
</form>
and the form used inside the jsx component:
<form name="contact" netlify netlify-honeypot="bot-field">
<Grid
container
rowSpacing={1}
columnSpacing={{ xs: 1, sm: 2, md: 3 }}
paddingLeft="28px"
className="Country-Code-grid"
>
<Grid item md={4} className="Country-Code-item">
<Item>
<Box
sx={{
"& .MuiTextField-root": {},
}}
noValidate
autoComplete="off"
>
<div className="Country-Code-field">
<Box
className="form_field"
sx={{ minWidth: 120 }}
>
<FormControl fullWidth>
<InputLabel
variant="standard"
htmlFor="uncontrolled-native"
className="form_control"
>
Country Code*
</InputLabel>
<NativeSelect
inputProps={{
name: "countrycode",
id: "uncontrolled-native",
}}
name="countrycode"
value={values?.countrycode}
onChange={handleChange}
>
{CountryCodeData &&
CountryCodeData.length > 0 &&
CountryCodeData.map((country, key) => (
<option
key={key}
value={country.dial_code}
>
{country.name} ({country.dial_code})
</option>
))}
</NativeSelect>
</FormControl>
</Box>
</div>
{errors.countrycode && touched.countrycode && (
<div className="error-message">
{errors.countrycode}
</div>
)}
</Box>
</Item>
</Grid>
<Grid item md={4}>
<Item>
<Box
sx={{
"& .MuiTextField-root": {},
}}
noValidate
autoComplete="off"
>
<div className="form_field">
<TextField
id="control-field"
label="Mobile Number"
type="text"
InputLabelProps={{
shrink: true,
}}
className="form_control"
name="mobilenumber"
value={values?.mobilenumber}
onChange={handleChange}
variant="filled"
/>
</div>
{errors.mobilenumber && touched.mobilenumber && (
<div className="error-message">
{errors.mobilenumber}
</div>
)}
</Box>
</Item>
</Grid>
<Grid style={{ marginTop: "2rem" }} item md={4}>
<LoadingButton
loading={sendingOtp}
className="form-btn form-processd-btn"
variant="contained"
onClick={handleVerify}
>
Send OTP
</LoadingButton>
</Grid>
</Grid>
</form>