The main difference is that: application/x-www-form-urlencoded
is not multipart/form-data
They submit different bodies, and that’s why I’ve been very confused with your use of new URLSearchParams(formData).toString()
See:
I wanted you to re-enable the file upload fields on the static file, both so that Netlify expects them as part of the submission, and so I could do a submission via it and show you that it works, and what the body looks like, and how it differs to what you’re currently sending.
my form has file inputs so what i read was that headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, is the wrong header type when you have file uploads, so you add enctype="multipart/form-data" to the __forms.html file instead and remove it from the fetch. Im trying to find the right combination of what to remove/keep and its just the same end result. Ok so going with your comment, what should body: new URLSearchParams(formData).toString() be then, lets go down that rabbit hole, may as well. im using next.js v 14 so theres a subset of docs for that.
Hopefully that clearly demonstrates the difference to you.
What you are sending via AJAX from your Next.js form doesn’t align with what submitting the form directly would do, it’s an entirely different Content-Type and body
I received 2 more form submissions, theres a div in both the __forms.html file and my next form: <div data-netlify-recaptcha="true" /> I added <input type="hidden" name="bot-field" /> as well.
my build was failing for other work i was working on, i finally sorted that out and was able to publish the changes with my form. I get a successful submission but there must be a delay in when i get a notification for the form, i dont see my own form submission in netlify.
Also in the network tab i dont see the payload anymore
i made a form submission on the actual website, i got my success message but i havent seen it show up in netlify form submissions list. But yes, your form submissions do have 2 test pages attached as pdfs.
Which obviously looks like it’s working, but I suspect it’s still not correct and that you won’t ever receive those submissions.
Things to try are:
Disable the recaptcha
Check if it works when the recaptcha is disabled on the form.
This isn’t me saying “you can’t have recaptcha”, it’s just a basic process of elimination.
Logging the values
Check what is inside the form data.
If you have recaptcha enabled, and aren’t sending g-recaptcha-response, then it won’t work.
This is in the documentation:
The Netlify servers will check the submissions from that form, and accept them only if they include a valid g-recaptcha-response value.
This is also suspicious, because I noticed the same:
However I personally don’t send multipart form data frequently enough to have any strong opinion on what the browser should/shouldn’t be displaying on any given request.
But it is an indication it probably doesn’t match what the static form sends when it is submitted.
Ok I removed the recaptcha but kept the honey pot field and the form sent immediately and i got the email notification. im going to try add <input type="hidden" name="g-recaptcha-response" /> to the nextjs form and bringing back recaptcha to see what it does.
Progress indeed! I got that 303 redirect thing as before when i added back data-netlify-recaptcha=“true”. How secure is just a honey pot? If thats enough ill probably just leave it at that. Also i never actually saw a recaptcha appear, so im that explains it.
They aren’t particularly effective these days, you can expect to inevitably start receiving spam.
Adding the data-netlify-recaptcha="true" to the static form causes Netlify’s post-processing to process the form in a way where it can only be submitted with a valid g-recaptcha-response value.
The static form is inserting recaptcha and doing this, which you can see if you make it visible:
i added <div data-netlify-recaptcha="true"></div> to my nextjs form and tried adding <input type="hidden" name="g-recaptcha-response" /> as well to it, i thought that would add it to the form data like the other hidden files? To start I dont see the recaptcha in the first place.
Where your “more advanced use case” is “your site is Next.js”
It becomes your responsibility to implement recaptcha, however that is done in the context of a Next.js site, but to ultimately ensure that a valid g-recaptcha-response value is sent.
Gotcha, its not accepting my netlify domain name. the site isnt hosted so maybe ill worry about this later and roll with the honey pot for now. thank you for all your help!