The Network request when a user submits a form comes from the client browser, so is always going to be related to your own front-end code and largely ‘out-of-scope’ for support here, but I’ll take a quick look and report what I can see.
That’s the case if it really is generating at least one static HTML file that contains the plain form with the appropriate Netlify attributes.
It isn’t the case, even when a site is “static”, if it’s constructed in a way where the form only exists within JavaScript and is injected into the HTML at runtime (some SPA’s [Single Page Application’s] operate like this).
In the case of the silverperkcoffee.com site, you can see that the form exists in the main /index.html page by using the browsers view source feature on the homepage, so it should be picked up…
Except you’re also using also using Next which is a whole other thing to consider, since factoring in things like SSR it’s entirely possible that page was generated at runtime and didn’t exist when the site was processed by Netlify’s build systems.
A possible indication of this is that the data-netlify="true" attribute is still there, and the documentation very clearly states that is removed when the form is processed:
Thank you so much for breaking that down for me. I think I understand a little better now, and I have a theory. The only difference between the 2 sites I made using the same code for a contact form is that the working website has the contact form as a separate page. That probably means that NextJS generates the html for that page separately from the main index.html file. I’ll investigate this a little more and report back.
I’ll also do a bit of extra reading to try and understand what my best fix for this would be. Not sure if I want a separate contact form, or if I should use a different approach.
So I suspect you meant to say just that the form isn’t being received.
As mentioned there is likely multiple things preventing the form from working, but even if all others were correct, this form still wouldn’t be received by Netlify’s systems because it’s missing the requiredform-name value.
Could you help me figure out where you are getting this network request? Here is my attempt at making a form submission, but as you can see, I’m not making any requests aside from the 2 images (which should be cached anyhow )
I’m not sure what you are referring to regarding the missing form-name as it isn’t something I’ve utilized before.
The link you sent me has the following <input type="hidden" name="form-name" value="name_of_my_form" />
Apologies for the delay. I was trying to trigger a branch deploy to make this process easier with changes. I was having issues, but I figured it out: https://staging--silverperkcoffee.netlify.app/
I moved the contact form to a seperate page, but it is still not being detected by the Netlify UI
If you check the Next.js specific information that I linked you will see that it requires that you POST to a route that is a static file, (so not one being handled by Next.js).
It’s another reason they get you to create a static HTML form file, as it not only aids the detection of the form but gives you a route to submit to for simplicity.
You’ll find your /success route isn’t a static file.
Dang, so I wonder why the other website is working
Seems I should go over the docs once more without thinking like it should be working as the other site does. Whatever the difference between them, I’ll figure out later.
Apologies for all the back-and-forth due to my ignorance on the subject. Thank you so much for your help. I’ll respond as soon as I have any updates!
So I have made some progress, but still having issues so apologies in advance if I missed something else. I promise you I’m really trying my best!
So as you can see at the end, I’m actually getting the form section of Netlify to show it is detecting the form, but I’m still unable to get any submissions to show up.
and the new tsx code (note that I was having issues with types so I added an ignore just while testing as it was unhappy about it otherwise saying: Argument of type 'FormData' is not assignable to parameter of type 'string | Record<string, string> | string[][] | URLSearchParams | undefined'. Type 'FormData' is missing the following properties from type 'URLSearchParams': size, sort
I am so sorry I took up so much of your time just because I thought it “should” have worked since it works on another similar sight. As you can see, it is working properly now. Thank you for walking me through this, truly!!!
@Light No problem, I’m much the same, in your position I’d now go back and try and confirm precisely why the previous one works, checking things like what version of Next.js and the ‘runtime’ are being used, where it’s posting to, if it’s a static file etc.
That’s what I’ve been doing for the past few hours today, but so far I haven’t found the difference. It must be something small that I technically saw and just didn’t register. Planning on chilling for the rest of the evening and hoping that tomorrow it’ll make sense with a refreshed brain haha
I apologize if this has already been mentioned. You can also compare your form code with the form mentioned in our Next.js 13.5 docs here:
Netlify Forms. If you’re using Netlify Forms, you will need to extract your form definitions to a dedicated static HTML file, and change the form submission to use AJAX rather than full-page navigation. A live demo is available here (see also: source code for the form component and the required static HTML file).