Hello,
I’m trying to set up a Netlify form to send messages from my site.
The form is working (messages are correctly submitted), but I can’t get the AJAX part to work.
On submit, I don’t want the user to be redirected to a thank you page. I want to display a Bootstrap alert with a success/error message under the form.
I have followed the official guidelines but I can’t remove the redirection. No matter what I do I keep on being redirected to Netlify’s default thank you page.
I have searched the forum already but haven’t found a solution for my case. Most user cases are for React. My project is based on Bootstrap, Eleventy and webpack.
Hello @raffaellarinaldi , thanks for posting and sharing a code snippet.
I took a look at the code you shared.
Reasons why you are having problems with your Ajax Form Submission.
You did not add the action attribute to your form.
You registered the Submit Event listener before defining the Submit Event handler function. Therefore the event handler function is undefined.
The HTML DOM element property innerHTML is NOT supposed to be a function.
Kindly make the changes to your HTML and JS code to match the code below.
For the HTML, add the action attribute to your form and set the value to "/". Note that the value of the action attribute of the form thus "/" must match the URL path in your fetch request.