gpt4 book ai didi

javascript - Vue.js Netlify 表单提交无法重定向到自定义感谢页面

转载 作者:行者123 更新时间:2023-11-28 03:28:49 25 4
gpt4 key购买 nike

在 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

最佳答案

看起来您已经做了所有可能的事情。在这个阶段,我不得不猜测 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
}
}
}

关于javascript - Vue.js Netlify 表单提交无法重定向到自定义感谢页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58368403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com