简体   繁体   English

为什么我的 Netlify 联系表不起作用?

[英]Why isnt my Netlify Contact Form working?

So Ive been racking my brain, watching tutorials, and trying everything in general.所以我一直在绞尽脑汁,看教程,尝试一切。 The Netlify docs are a bit hazy on how to do it and the tutorials Ive watched conflict with it a little in the general code set up. Netlify 文档对如何做有点模糊,我看过的教程在一般代码设置中与它有一点冲突。 Would any one mind giving feed back as to if this is the correct way and that my code is correct;是否有人会介意这是否是正确的方法并且我的代码是否正确? if not tell me what could be added or removed to make this work?如果不告诉我可以添加或删除什么来完成这项工作? I dont see any of the submissions I have tested in the form submission repository on Netlify.我没有看到我在 Netlify 的表单提交存储库中测试过的任何提交。

import React from 'react';
import Layout from '../components/layout';
import SEO from '../components/seo';
import './contact.scss';

const ContactPage = () => {
  return (
    <Layout>
      <SEO title="Contact" />
      <h2 style={{ textAlign: 'center' }}>Drop a line and say hi!</h2>
      <h1>Contact Me</h1>
      <div className="contactForm">
        <form name="contact" netlify netlify-honeypot="bot-field" hidden>
          <input type="text" name="name" />
          <input type="email" name="email" />
          <input type="subject" name="subject" />
          <input type="budget" name="budget" />
          <textarea name="message"></textarea>
        </form>

        <form
          name="contact"
          method="post"
          data-netlify="true"
          data-netlify-honeypot="bot-field"
          action="/success/"
          data-netlify-recaptcha="true"
        >
          <input type="hidden" name="form-name" value="contact" />

          <input type="text" name="name" placeholder="Your Name" />

          <input type="email" name="email" placeholder="name@name.com" />

          <input
            type="subject"
            name="subject"
            placeholder="Your Question?"
            style={{ width: '70%', float: 'left' }}
          />

          <input
            type="budget"
            name="budget"
            placeholder="Your Budget"
            style={{ marginLeft: '2%', width: '27%', float: 'left' }}
          />

          <textarea
            name="message"
            placeholder="Whats on your mind?"
            style={{ height: '100px' }}
          ></textarea>

          <div data-netlify-recaptcha="true"></div>

          <button type="submit">Send</button>
        </form>
      </div>
    </Layout>
  );
};
export default ContactPage;

If there is anything additional I can provide to help clarify this please let me know.如果我可以提供任何其他信息来帮助澄清这一点,请告诉我。 I just dont know what is good or not to add or take away from the code to get it to be submitted properly.我只是不知道在代码中添加或删除什么是好的,以使其正确提交。 Netlify does recognize that there is a form, but nothing seems to be submitted. Netlify 确实承认有一个表单,但似乎没有提交任何内容。

I can relate.我可以联系起来。 I had difficulties when I implemented it as well.我在实施它时也遇到了困难。

The one thing I notice from your code: Why do you have two form tags?我从您的代码中注意到的一件事:为什么您有两个表单标签? Remove the first form tag and all its content.删除第一个表单标签及其所有内容。 My guess is that because there are two forms with the same name are causing your problems.我的猜测是,因为有两个同名的 forms 导致您的问题。

Here is my form implementation which works on Netlify:这是我在 Netlify 上的表单实现:

        <form name="form-feedback" // important: Give your form a name
              method="POST" // important: make sure there is some way the data is transfered like here with an HTML request
              data-netlify="true" // important: enable your form in netlify
              netlify-honeypot="bot-field"
              action="/thanks">

          <input name="form-name" value="form-feedback" type="hidden" />
          {/* important: value="form-feedback" needs to be the same as defined in the form tag*/}

          {/* your form fields */}
          <div>
            <Typography variant="body1" gutterBottom>More Feedback</Typography>
            <Input
              type="text"
              name="generalFeedback" // important: give your inputs a name
              placeholder="More Feedback"
              multiline
            />
          </div>

          {/* important: Your form needs to be submitted somehow */}
          <Button type="submit" value="Submit">Send Feedback</Button>
        </form>

The important bits are commented with important: .重要的位用important:

Another tip: Create a barebones project that only has the form as a component in its index page.另一个提示:创建一个仅将表单作为其索引页面中的组件的准系统项目。 Then create a dummy site you can upload to netlify and test your form in this isolated environment.然后创建一个虚拟站点,您可以上传到 netlify 并在这个隔离环境中测试您的表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM