简体   繁体   English

谢谢你提交表格提醒

[英]Thank you alert upon form submission

I have a very basic form at http://www.happyholidaylites.com/contact.html and it is working great. 我在http://www.happyholidaylites.com/contact.html上有一个非常基本的表格,它运作良好。 When you submit the form, the user is brought to the index.html with no message that the form has been sent. 当您提交表单时,用户将被带到index.html,而不会发送表单已发送的消息。 I am looking to initiate an alert that says, "your form has been submitted" with an x button. 我希望通过x按钮发出一条提示“已提交表单”的提醒。 My code looks like this: 我的代码看起来像这样:

      <form method="post" id="myForm" action="dynaform.php">

      <input type='hidden' name='rec_mailto' value='JBIRD1111@gmail.com'>
      <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. 最后一行是告诉表单在按下提交按钮后要做什么,但我不希望它将浏览器指向索引,而是我想要一个带有成功消息的javascript弹出窗口。 Any ideas? 有任何想法吗?

为什么不简单的onSubmit?

<form method="post" id="myForm" action="dynaform.php" onSubmit="alert('Thank you for your feedback.');" >

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 . 看看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. 您应该创建一个名为“thank-you.html”的页面,您可以将用户重定向到成功提交的页面,该页面可以访问站点导航选项,或者甚至只需几秒钟后重新定向到表单页面。

Instead of redirecting to index.html, redirect to thanks.html; 而不是重定向到index.html,重定向到thanks.html; your users will thank you because everybody hates popups! 你的用户会感谢你,因为每个人都讨厌弹出窗口!

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. 听起来像PHP脚本通过处理输入并将浏览器重定向到rec_thanks字段中的值来处理表单提交。

You can add something like onsubmit="YourJavaScriptFunction()" to the form tag to add client-side behavior prior to actually submitting the form. 您可以在表单标记中添加类似onsubmit="YourJavaScriptFunction()"以便在实际提交表单之前添加客户端行为。 Within that function you can perform validation, use alert('Thank You!') , etc.. 在该功能中,您可以执行验证,使用alert('Thank You!')等。

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

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