Vue.js Netlify表单提交无法重定向到自定义“谢谢”页面

时间:2019-10-13 22:53:21

标签: javascript vue.js netlify

在Vue.JS中创建表单,并与Netlify的表单提交处理程序连接。 无法重定向到自定义的谢谢页面。 Netlify的默认“谢谢”页面总是出现。

在文档和论坛上搜索了一段时间,但无济于事。

我正确设置了路由,以处理新页面/成功。 在下面,您可以看到我已向表单添加了一个操作,该操作应采用正确的格式。

我认为问题可能与Vue.JS路由有关,或者是Netlify识别/ success是否为活动组件/页面的方式。如netlify文档中所述,如果操作路径无效,则它将自动默认返回netlify的“谢谢”页面。

https://github.com/DanielGibsonOrchid/freightlegend

https://freightlegend.netlify.com/

        <form 
          action="/success"
          class="get-started-form" 
          name="get-started" 
          method="post" 
          data-netlify="true"
          data-netlify-honeypot="bot-field"
        >
          <input type="hidden" name="bot-field" />
          <input type="hidden" name="form-name" value="get-started" />
          <div class="form-content flex">

            <input type="text" name="name" placeholder="Your name" class="input-main" required />
            <input type="email" name="email" placeholder="Your email" class="input-main input-margin" required />
            <div class="select-div">
              <select name="country" class="input-main">
                <option value="New Zealand">New Zealand</option>
                <option value="Australia">Australia</option>
                <option value="USA">USA</option>
                <option value="Other">Other</option>
              </select>
            </div>
          </div>
          <input type="submit" class="btn-main" />
          <!-- <button type="submit" class="btn-main">Submit Query</button> -->
        </form>

public/_redirects

/locale.json  /locales/us.json  302  Country=us
/locale.json  /locales/au.json  302  Country=au
/locale.json  /locales/nz.json  302  Country=nz

/*            /index.html       200

1 个答案:

答案 0 :(得分:0)

看起来您已经完成了几乎所有可能的事情。在这个阶段,我不得不猜测Netlify无法处理将自定义成功页面与SPA结合使用。

我会改用AJAX form submission

例如

<form @submit.prevent="handleFormSubmit" ...>
methods: {
  async handleFormSubmit ($event) {
    const form = $event.target
    const body = new URLSearchParams(new FormData(form))
    try {
      const res = await fetch(form.action, { method: 'POST', body })
      if (res.ok) {
        this.$router.push({ name: 'thanks' })
      } else {
        throw res
      }
    } catch (err) {
      console.error(err)
      // you don't have an error page but maybe you should add one
    }
  }
}