Hidden form field not being submitted

Here is the site name

The site is built on react, rendered with gatsby, and hosted on netlify.

Good morning!
The contact form on this site is at the bottom of each page and it has been working. However I am attempting to add a hidden field that sends the url of the page the user was on when they submitted the form. I have the hidden input added in the source code and it is in place properly, using dev tools I am able to see that the value is tracking the url properly, but when the form is submitted that field does not show up in the submission. I have tried making the field not hidden and whenever I do that it is sent properly with the form submission.
Is there something additional that needs added for the hidden field to be sent in with the form submission?

Here is the block of code where I am trying to add the field. Please note that the line is encased in a check if window is undefined so that it renders in gatsby properly.

<form
   method="post"
   action="/thank-you/"
   data-netlify-honeypot="bot-field"
   data-netlify="true"
   name="Contact Form"
   className={formClassName ? formClassName : "form"}
>
   <input type="hidden" name="form-name" value="Contact Form" />
   <input type="hidden" name="bot-field" />
   {typeof window !== 'undefined' &&
      <input type="hidden" name="referrer" value={window.location.href} />
   }

Thank you for any help you can provide!

The input doesn’t seem to exist in the HTML source:

I’m assuming, because you’ve added it as a condition, it’s getting dynamically added via JavaScript.

I can confirm this by disabling JavaScript:

As you can see, the input doesn’t exist in the DOM. Netlify form only process input that exist when the build bots parse the HTML.

So, you’ve 2 options:

  1. Submit the form using JavaScript and add the required filed while submitting.

  2. Add a static HTML version of your form somewhere in the website so the build bot can parse the hidden input.

1 Like

Thank you so much for your help! That was the problem, I was able to fix it by adding a line outside of the condition that defines the field and then I add the value within the condition.