感谢您在提交表格时发出提醒
我有一个非常基本的表格 http://www.happyholidaylites.com/contact.html而且效果很好。当您提交表单时,用户将被带到index.html,并且不会显示表单已发送的消息。我希望通过 x 按钮启动一条警报,提示“您的表单已提交”。我的代码如下所示:
<form method="post" id="myForm" action="dynaform.php">
<input type='hidden' name='rec_mailto' value='[email protected]'>
<input type='hidden' name='rec_subject' value='New Contact Form'>
<input type='hidden' name='rec_thanks' value='index.html'>
依此类推......
最后一行是告诉表单按下提交按钮后要做什么,但我不希望它将浏览器指向索引,而是我想要一个带有成功消息。有什么想法吗?
I have a very basic form at http://www.happyholidaylites.com/contact.html and it is working great. When you submit the form, the user is brought to the index.html with no message that the form has been sent. I am looking to initiate an alert that says, "your form has been submitted" with an x button. My code looks like this:
<form method="post" id="myForm" action="dynaform.php">
<input type='hidden' name='rec_mailto' value='[email protected]'>
<input type='hidden' name='rec_subject' value='New Contact Form'>
<input type='hidden' name='rec_thanks' value='index.html'>
so on and so forth.....
The last line is what is telling the form what to do after the submit button is pressed, but I dont want it to point the browser to the index, rather I want a javascript popup with a success message. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为什么不一个简单的 onSubmit?
Why not a simple onSubmit?
老实说,您最好重定向到另一个页面,以避免用户在刷新时重新提交页面。查看Post/Redirect/Get 模式。
网站上的弹出窗口可能非常烦人。您应该创建一个名为“thank-you.html”的页面,您可以在成功提交后将用户重定向到该页面,该页面可以访问站点导航选项,甚至可以在几秒钟后重定向回表单页面。
To be honest you are better re-directing to another page in order to avoid the user re-submitting the page on a refresh. Have a look at Post/Redirect/Get Pattern.
Popups can be extremely annoying on websites. You should create a page called "thank-you.html" that you can re-direct the user to on successful submission which has access to the site navigation options or even just do a re-direct back to the form page after a few seconds.
不重定向到index.html,而是重定向到thanks.html;您的用户会感谢您,因为每个人都讨厌弹出窗口!
Instead of redirecting to index.html, redirect to thanks.html; your users will thank you because everybody hates popups!
听起来您的 PHP 脚本通过处理输入并将浏览器重定向到
rec_thanks
字段中的值来处理表单提交。您可以在表单标记中添加类似
onsubmit="YourJavaScriptFunction()"
的内容,以在实际提交表单之前添加客户端行为。在该函数中,您可以执行验证、使用alert('Thank You!')
等。Sounds like your PHP script handles the form submission by processing the input and redirecting the browser to the value in the
rec_thanks
field.You can add something like
onsubmit="YourJavaScriptFunction()"
to the form tag to add client-side behavior prior to actually submitting the form. Within that function you can perform validation, usealert('Thank You!')
, etc..