Form submission

I set up a form on my site which I believe I did correctly. The headers in the network tab show a POST request and all the form data being sent plus a redirect status 303. I added an email notification in the notification area. However, when I test the form, I receive no notification and nothing saying the form was even submitted in the netlify console.

Can I see your code?

Maybe also Insert some screenshots of your console (netlify).

Thanks

1 Like

No luck. Here’s the important code:

function encode(data) {

return Object.keys(data)
.map(key => encodeURIComponent(key) + ‘=’ + encodeURIComponent(data[key]))
.join(’&’);
}

export default function Contact() {
const [state, setState] = React.useState({});
const recaptchaRef = React.createRef();

const handleChange = e => {
setState({ …state, [e.target.name]: e.target.value });
};

const handleSubmit = e => {
e.preventDefault();
const form = e.target;
const recaptchaValue = recaptchaRef.current.getValue();
fetch(’/’, {
method: ‘POST’,
headers: { ‘Content-Type’: ‘application/x-www-form-urlencoded’ },
body: encode({
‘form-name’: form.getAttribute(‘name’),
‘g-recaptcha-response’: recaptchaValue,
…state,
}),
})
.then(() => navigate(form.getAttribute(‘action’)))
.catch(error => alert(error));
};

return (




This form won’t work with Javascript disabled





Your name<span style={{ color: ‘red’ }}>:







Your email<span style={{ color: ‘red’ }}>:







Your phone<span style={{ color: ‘red’ }}>:







Tell Us About Your Project<span style={{ color: ‘red’ }}>:

















);
}

I removed the Recaptcha and it started working. Not sure what that’s all about. Thanks

2 Likes

Ok i can give you my code of my form (with honeypot form and recaptcha) if you want to

But I’m glad its working now

Greetings

TRG

2 Likes