提交表格并与nuxt2重定向
我正在努力与NUXT2建立一个简单的联系表格,希望用户在提交表格及其详细信息后将用户重定向到主页。
这是我现在在表格上获得的核心。经过数小时的玩法,我无法提交和重定向。
<form action="mailto:[email protected]" method="POST" @click="window.location.href = 'https://company.com/';">
<div>
<div>
<input type="text" name="name" id="name" autocomplete="name" placeholder="Name">
</div>
<div class="col-span-6 sm:col-span-3">
<input type="email" name="email" id="email" autocomplete="email" placeholder="Email">
</div>
<div>
<textarea name="message" id="message" autocomplete="message" placeholder="Your Message"></textarea>
</div>
<div class="xl:w-1/3 md:w-1/2 px-4">
<a class="btn black-btn mt-2" type="submit" >Send Message</a>
</div>
</div>
</form>
任何帮助将不胜感激。谢谢你!
- 编辑:
我的表单工作正常,现在它向提供的邮箱提交了一条消息,但是我试图在提交表格时添加吐司通知以确认已发送消息。
这是我的新表单标签:
<form action="https://formsubmit.co/email" method="POST" @submit.prevent="formSubmit">
这是
methods: {
formSubmit() {
this.$router.push("/");
this.$toast.show('Message sent')
},
}
当前在我的脚本标签中,我在提交表单后没有获得“我不是机器人”复选框。 但是,当我添加@submit =“()=&gt; form ubmit(true)”
在我的表单标签中,然后删除此this。$ router.push(“/”/ >从方法中,它提交表单,然后进行机器人检查,这不是应该的方式。我已经玩了一段时间了,无法弄清楚。 如果有人有建议,这将不胜感激!
I'm working on building a simple contact form with Nuxt2 where I'd like the user to be redirected to the homepage after submitting the form with their details.
This is the core of what I've got on the form right now. After hours of playing around, I can't get it to submit and redirect.
<form action="mailto:[email protected]" method="POST" @click="window.location.href = 'https://company.com/';">
<div>
<div>
<input type="text" name="name" id="name" autocomplete="name" placeholder="Name">
</div>
<div class="col-span-6 sm:col-span-3">
<input type="email" name="email" id="email" autocomplete="email" placeholder="Email">
</div>
<div>
<textarea name="message" id="message" autocomplete="message" placeholder="Your Message"></textarea>
</div>
<div class="xl:w-1/3 md:w-1/2 px-4">
<a class="btn black-btn mt-2" type="submit" >Send Message</a>
</div>
</div>
</form>
Any help would be appreciated. Thank you!
-- edit:
I have got the form working and it now submits a message to the mailbox provided, however I'm trying to add a toast notification to appear upon submitting the form to confirm that the message is sent.
This is my new form tag:
<form action="https://formsubmit.co/email" method="POST" @submit.prevent="formSubmit">
And this is in my script tag
methods: {
formSubmit() {
this.$router.push("/");
this.$toast.show('Message sent')
},
}
Currently I don't get the "I'm not a robot" Checkbox upon submitting the form.
But when I add @submit="() => formSubmit(true)"
inside my form tag, and remove this this.$router.push("/")
from the methods, it submits the form and then does the robot check, which is not how it should be. I've been playing around with this for a while and can't figure it out.
If anyone has a suggestion, it would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请使用
@submit
而不是@click
,并使用&lt; button type =“ smind&gt;&gt;/butt;/button&gt;
而不是标签。Please use
@submit
instead of@click
, and use<button type="submit></button>
instead of a tag.将您的表格更改为这样,
并在您的方法中使用名称form ubmit中添加一种方法,类似
change your form to be like this
and add a method in your methods with the name formSubmit, something like