-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not Receiving Form Submissions via Netlify Forms #12040
Comments
@deeheber a quick glance at your code repository i saw that you have
This because at first glance, it looks like the service worker might be the culprit. |
Hey @jonniebigodes thanks for the reply! I tried those things out and am still experiencing the same issue. Noticing it flashes a 404 page real quick and then redirects to the Looked at my form submissions and did get one at 10:49AM PT from a Dustin at Gatsby...unsure how he successfully submitted that. I have my netlify setup to auto deploy when I push to master, so what's in master is what's up on the live netlify site. |
@deeheber I didn't do anything special--just filled out the form! I did disable the service worker, but that seems like a sorta unlikely culprit. Happy to debug this further, but at first glance--this seems like a Netlify issue rather than a Gatsby issue. I may recommend checking out some of these resources: |
Sounds good @DSchau. I sent an email to Netlify asking for input from them. |
@deeheber Did you hear anything back from Netlify? I'm experiencing the same issue. |
@j-651 They said they thought it was the service worker (the |
I would love for someone to help me figure this out. I am having the same exact problem as deeheber. I've tried just about every little thing I could find after endless googling... |
@valdezDev i picked up on your comment and i was able to connect Gatsby and netlify forms. Here are the steps i took
import React from "react"
export default () => (
<form
name="contact"
method="post"
action="/success"
data-netlify="true"
data-netlify-honeypot="bot-field"
>
<input type="hidden" name="bot-field" />
<div>
<label htmlFor="name">Name</label>
<input type="text" name="name" id="name" />
</div>
<div>
<label htmlFor="email">Email</label>
<input type="text" name="email" id="email" />
</div>
<div>
<label htmlFor="message">Message</label>
<textarea name="message" id="message" rows="6" required />
</div>
<div>
<input type="submit" value="Drop a line" />
<input type="reset" value="Eraser" />
</div>
</form>
)
import React from "react"
import DummyForm from "../components/dummyForm"
export default () => (
<div>
<h2>Send me a line</h2>
<DummyForm/>
</div>
)
import React from "react"
export default () => (
<div>
<h2>You dropped me a new line</h2>
<h4> Congrats,i'll be sure to check it out when i can and add a reply</h4>
</div>
)
As you can see both submissions were added with success. I hope my reproduction can help you solve your issue. If not. feel free to add a minimal reproduction of your issue. Feel free to provide feedback |
Hi @jonniebigodes thank you so much for taking the time to help me troubleshoot this issue. I will start by posting the link to my repo: https://github.com/valdezDev/gatsby-portfolio so you can refer to commits if needed. I know my code might look a little bit messy at the moment. I got my form to work by doing exactly what you suggested and found that it can only work on the index page. Do you think there's any way that I can have this wire up in the same way on my contact page with the same functionality? If not, I can readjust my index page to incorporate the contact form. Thanks again! |
@valdezDev What I did to fix this issue, first confirm you have the hidden input field for the bot detection when using honey bot, make sure all the other essentials are covered you can refer to the Forms. Once you can confirm you did all of this then go into your developers tab look at the Post data which can be found under the network tab. check to see if the request is truncating your post form name, you can confirm this by comparing the post parameters. First preserve the log then disable javascript sumbit a form request, confirm that the form is submitted to Netlify. If it was submitted then I urge you to refer to this piece of code. |
Strangely, having a field with name |
Why did this get closed? I'm having the exact same issue as others here. |
@gastongarcia this isn't a Gatsby issue. |
@KyleAMathews You're right. Here's a the fix that probably everyone needs: For Netlify Forms, if you're using a SSG like Gatsby, a hidden input field with the form name is needed. Without this it won't work. |
I will be soon publishing a YouTube video as well as a blog post going over
this issue if anyone is interested. As I've stated before, I found that a
correctly set up Netlify form can only work on the index page that the
gatsby boilerplate provides the dev. I had it set up so that the user would
have to navigate to a 'contact' page where the form would be and I would
only get 404 errors. If anyone wants to peek at my unfinished portfolio
code base, feel free! https://github.com/valdezDev/gatsby-portfolio
…On Sat, Apr 27, 2019 at 6:24 PM Gaston Garcia ***@***.***> wrote:
@KyleAMathews <https://github.com/KyleAMathews> You're right.
Here's a the fix that probably everyone needs:
For Netlify Forms, if you're using a SSG like Gatsby, a hidden input field
with the form name is needed. Without this it won't work.
https://www.netlify.com/blog/2017/07/20/how-to-integrate-netlifys-form-handling-in-a-react-app/#step-2
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12040 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AH6IEIB2PT72ULYHQNMYUK3PSTHDHANCNFSM4GZ2ZC7A>
.
|
Catch up on this and it looks like my reproduction not the one above, but the one directed specifically at valdezDev magically disappeared. Humm interesting......Anyway, I've made a pull request to valdezDev repository and you can see there the code i used to make it work. |
You can have the contact form wherever you want. As I posted above, the problem is not having the hidden input field. When using a Static Site Generator it's best to set it up that way. |
@duongthienlee if you check the network tab on your development tools you're probably seeing that you're getting some 404. The code below was the one used to correct the issue at hand, it worked for @valdezDev in my now missing comment when i made a reproduction for solving the issue for him. import React, { Component } from "react"
import { navigate } from "gatsby"
class ContactForm extends Component {
constructor(props) {
super(props)
this.ContactForm = React.createRef()
this.state = {}
}
encode = data => {
return Object.keys(data)
.map(key => encodeURIComponent(key) + "=" + encodeURIComponent(data[key]))
.join("&")
}
handleChange = e => {
this.setState({ [e.target.name]: e.target.value })
}
handleSubmit = e => {
e.preventDefault()
const form = this.ContactForm.current
fetch("/", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: this.encode({
"form-name": form.getAttribute("name"),
...this.state,
}),
})
.then(response => {
console.log("====================================")
console.log(`${JSON.stringify(response, null, 2)}`)
console.log("====================================")
navigate(form.getAttribute("action"))
})
.catch(error => {
console.log("====================================")
console.log(`error in submiting the form data:${error}`)
console.log("====================================")
})
}
render() {
return (
<form
name="contact"
method="post"
action="/success/"
data-netlify="true"
data-netlify-honeypot="bot-field"
onSubmit={this.handleSubmit}
ref={this.ContactForm}
>
<input type="hidden" name="form-name" value="contact" />
<p hidden>
<label>
Don’t fill this out:{" "}
<input name="bot-field" onChange={this.handleChange} />
</label>
</p>
<p>
<label>
Your name:
<br />
<input type="text" name="name" onChange={this.handleChange} />
</label>
</p>
<p>
<label>
Your email:
<br />
<input type="email" name="email" onChange={this.handleChange} />
</label>
</p>
<p>
<label>
Message:
<br />
<textarea name="message" onChange={this.handleChange} />
</label>
</p>
<p>
<button type="submit">Send</button>
<input type="reset" value="Eraser" />
</p>
</form>
)
}
}
export default ContactForm see if the code above helps you in any shape or form and report back. |
@duongthienlee glad to hear it. I'm leaving the code here, so that future people that come across this issue could try the code i posted and see if it helps them in any way, shape or form and with that avoid creating further issues in here. |
I'm having the same issue. I have actually been able to make this work on a previous project without a hitch, but have not been able to replicate it. I have adapted @jonniebigodes code, but I still keep getting a 404 error. Specifically, the console.log of the response returns empty. |
Can confirm that the stringified response returns empty, but the form does submit successfully for me. |
@orshick and @MirelesCloud the |
This worked for me also |
I'm still getting a 404 when submitting a Netlify form from my Gatsby site. Here's my code:
I just put some dummy data in the request, and otherwise have followed the instructions provided by Netlify and in this thread. |
EDIT: Made a blog post on debugging GatsbyJS forms with Netlify. Hi all - just been stung by this & found the issue. Hopefully this will help people debug.
|
Hi all , i had the same problem and i solved it , all i did is Empty Cache and Hard Reload in the browser . To do so : press F12. This opens the Chrome Developer Tools. Next, right-click on the browser Reload button click on Emty Cache and hard reload . I hope it works for you all . |
Hi everyone, Just had a similar problem, was sending the form, was redirected to my success page, but nothing on netlify. For me the issue was using Here is the working code for my case <form
name="form-contact"
action="/contact-thank-you"
className="tr"
netlify="true"
method="POST"
netlify-honeypot="not-today"
>
<Input label="Ton Email" name="email" type="email" required />
<input name="not-today" hidden />
<input name="form-name" value="form-contact" hidden />
<Textarea label="Ton Message" name="message" required />
<Button icon="fa-paper-plane" type="submit">
Envoyer
</Button>
</form> Input, Textarea and Button components are just for styling, nothing fancy/hidden happening there. import React from "react"
const Button = ({ children, icon, ...props }) => {
return (
<button
{...props}
className="border-box f5 f4-ns tc mid-gray pv2 ph4 br-pill b--mid-gray bg-transparent bw1 ba"
>
{children}
<i className={`fas ${icon} ml2`} />
</button>
)
}
export default Button I hope this can help someone someday :) |
For what it's worth, this did NOT work for me using the framework Angular. It may still be necessary, but it didn't solve the problem. |
Hello, I have read all the comments on this issue because I have the same problem. This handleSubmit function works for me in Local (200 res), but once deployed in Netlify, throws a 404 error. It is strange because I can see the page where I am redirected once the form is submitted(/success page). |
I had the same issue, it worked whene i added hidden fields to the form |
@jonniebigodes code worked for me! Thank you!. I would remember that when using hooks set state this way |
@Lucascoorek that's great. Glad to hear it that it worked for you. And it goes without saying, really no need to thank, just glad that the code/comment helped you aswell. |
It appears that Gatsby strips the form name from the form submission. By adding the hidden field you can restore the name and don't run into submission issues. Example code from -> https://codebushi.com/form-handling-gatsby-netlify/ Other have run into this issue at -> gatsbyjs#12040
It appears that Gatsby strips the form name from the form submission. By adding the hidden field you can restore the name and don't run into submission issues. Example code from -> https://codebushi.com/form-handling-gatsby-netlify/ Other have run into this issue at -> #12040 Co-authored-by: gatsbybot <[email protected]>
…ld for Netlify Forms (#24548) It appears that Gatsby strips the form name from the form submission. By adding the hidden field you can restore the name and don't run into submission issues. Example code from -> https://codebushi.com/form-handling-gatsby-netlify/ Other have run into this issue at -> gatsbyjs/gatsby#12040 Co-authored-by: gatsbybot <[email protected]>
It appears that Gatsby strips the form name from the form submission. By adding the hidden field you can restore the name and don't run into submission issues. Example code from -> https://codebushi.com/form-handling-gatsby-netlify/ Other have run into this issue at -> gatsbyjs/gatsby#12040 Co-authored-by: gatsbybot <[email protected]>
It appears that Gatsby strips the form name from the form submission. By adding the hidden field you can restore the name and don't run into submission issues. Example code from -> https://codebushi.com/form-handling-gatsby-netlify/ Other have run into this issue at -> gatsbyjs/gatsby#12040 Co-authored-by: gatsbybot <[email protected]>
It appears that Gatsby strips the form name from the form submission. By adding the hidden field you can restore the name and don't run into submission issues. Example code from -> https://codebushi.com/form-handling-gatsby-netlify/ Other have run into this issue at -> gatsbyjs/gatsby#12040 Co-authored-by: gatsbybot <[email protected]>
It appears that Gatsby strips the form name from the form submission. By adding the hidden field you can restore the name and don't run into submission issues. Example code from -> https://codebushi.com/form-handling-gatsby-netlify/ Other have run into this issue at -> gatsbyjs/gatsby#12040 Co-authored-by: gatsbybot <[email protected]>
It appears that Gatsby strips the form name from the form submission. By adding the hidden field you can restore the name and don't run into submission issues. Example code from -> https://codebushi.com/form-handling-gatsby-netlify/ Other have run into this issue at -> gatsbyjs/gatsby#12040 Co-authored-by: gatsbybot <[email protected]>
Just wanted to let everyone know this helped me a ton so grateful for all of you, thanks! |
Changing |
It appears that Gatsby strips the form name from the form submission. By adding the hidden field you can restore the name and don't run into submission issues. Example code from -> https://codebushi.com/form-handling-gatsby-netlify/ Other have run into this issue at -> gatsbyjs/gatsby#12040 Co-authored-by: gatsbybot <[email protected]>
It appears that Gatsby strips the form name from the form submission. By adding the hidden field you can restore the name and don't run into submission issues. Example code from -> https://codebushi.com/form-handling-gatsby-netlify/ Other have run into this issue at -> gatsbyjs/gatsby#12040 Co-authored-by: gatsbybot <[email protected]>
What actually worked for me is to include the same form I had in my contact.component.hml in the index file and then added the hidden attribute: Finally: I was using all these form validators in angular, FormControl, FormGroup, Validators and that was a waste of time. Just follow the above and you should be good. |
Summary
Hey there disclaimer that I'm new to using Gatsby, but I'm having some troubles with getting my form to submit properly using Netlify forms. Unsure if this is a Gatsby or Netlify related problem.
Steps to reproduce:
Any additional input you can provide would be very helpful and appreciated. Did a quick scan of open issues and wasn't able to locate anything that looked related.
Thanks for your work on this open source project...aside from this issue using Gatsby has been great thus far!
Relevant information
404
error for thePOST
to/success
after submitting the form via the live site deploy on Netlify in my Chrome dev tools > Network tabgatsby-remark-images
, did anrm -rf
of mynode_modules
and mypackage-lock.json
and did a freshnpm i
Environment (if relevant)
The text was updated successfully, but these errors were encountered: