[Support Guide] I don't see form submissions when using JavaScript

Last reviewed by Netlify Support on May 25, 2022

I have a form rendered using JavaScript, but it’s not submitting. What’s going on?

There are a few things to consider when using JavaScript with a Netlify-handled form:

  1. If you have rendered your form using JavaScript and are not using a Static Site Generator (or, your generator does not render it down to HTML such as Gatsby does), you will need to make sure you have a hidden, pure HTML version of your form somewhere in your site.

    • This means a file ending in .html that has a definition starting with <form ..... Our form-handling is only able to parse these HTML forms at deploy time to prepare our service to receive form submissions.
  2. If you have defined your form using JavaScript, but are not using JavaScript to submit the form, you will need to add the following hidden field:

    <input type="hidden" name="form-name" value="your-form-name" />
    

    where the value is the name of your specific form.

    • This is necessary to enable correct form submissions on top of the static HTML version of the form. The form-name hidden field tells our system the name of the form where the submission originated. Unless you have explicitly provided the form-name in your JavaScript, you will need to provide it as described above because our system is unable to add it onto JavaScript rendered forms.
  3. If you are using JavaScript to submit your form, you’ll need to make sure that the form data being sent has the same fields (the name=, including spelling and punctuation, must be identical) as in HTML version. Don’t forget to include the form-name field as mentioned above!

JavaScript opens up a lot of possibilities; awesome, right?

If you have any other questions, please leave us a comment below :slightly_smiling_face:

1 Like

Update - setting the resource/url parameter for fetch() to the active redirect base successfully records the form submission in Netlify:
fetch('/en', ...)

Hi! thanks for the post. I’m able to submit via JS fetch() (without a honeypot field even), but when I enable the following language based redirects the submissions don’t go through. Any thoughts? Thanks!

// _redirects
/ /es 302 Language=es
/ /en 302
// submit via fetch()
netlifyFormSubmit (name, data) {
  const encode = (data) => {
    return Object.keys(data)
      .map(key => encodeURIComponent(key) + '=' + encodeURIComponent(data[key]))
      .join('&')
  }
  return fetch('/', {
    method: 'POST',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    body: encode({ 'form-name': name, ...data })
  })
}
1 Like

Could you link us to your form in production so we can see it in action, @evvvritt ? Hard to tell what is happening without more context - such as the meaning of “don’t go through” - HTTP 404? missing submissions? Empty submissions?

Knowing where to find your form would help us out a lot. If you don’t want to post the URL here, you could say “netlify site ID # X and the form is at /path on deploy ID Y”. You can find the site ID on the general settings page, and the deploy ID will be in the URL from the logs for the deploy you were testing on (last component: Netlify App).

Hello, I´m deploying my first site through Netlify these days. I´m currently having a html form that gets some additional select/option elements from the DOM depending on what they have searched on. My form submits to Netlify, but I cant get the additional JS elements to submit its value and I dont get where I should add the <input type="hidden" name="form-name" value="contact" /> as stated above. What am I missing?

Thanks,
Nikolai

Hi, @NikolaiLadeklar, when a site is deployed with our service there is post processing which occurs. During this post processing any HTML <form> tags are processed and a backend handler is created to receive the form submisstions.

The handlers will only access fields defined in the HTML it processed. All other fields are silently dropped.

The solution for this is to have the HTML version of the form contain all possible fields. If this is done, the handler will be able to accept all field. Missing fields are allow but undefined fields are ignored.

If there are other questions about this, please let us know.

Great, thanks for the clarification!

I have a stateful react form with a static html hidden form, and all my fields are submitting successful except for one, which uses props to pass data into the value. Please check it out at this thread => Pass a hidden input value with stateful React form

We managed to get that one :arrow_heading_up: figured out :tada: Check out the linked thread if you’re having trouble with something similar.

Hi Luke,

Could there be a delay between ‘building’ a site, and ‘post processing any HTML forms’ ?

I have added an HTML form, but it doesn’t appear to be picked up in the build logs and it doesn’t appear in the Netlify UI.

The site URL is …

And the HTML page with the form (just so that Netlify will detect it, it’s not linked to) …

https://alihearn.com/netlify-needs-this-to-detect-the-subscribe-form/

Cheers,

Adrian

Ok, I got it to work by changing the ‘action’ attribute from …

action=“Subscribe Thanks | ALI HEARN | STUDIOS

… to just …

action=“/subscribe-thanks/”

Cheers,

Adrian

Thanks for sharing your solution, @Adrian_Parr.