简体   繁体   English

如何在刷新页面时停止“Conform form resubmission”对话框

[英]How to stop 'Conform form resubmission' dialog while refreshing the page

I am using an subscribe script to add the user email address to mysql record. 我使用订阅脚本将用户电子邮件地址添加到mysql记录。 I used the below code for this process .It works fine .after user submit the email the page is refreshed and database is also updated to mysql :-) . 我使用下面的代码进行此过程。工作正常。用户提交电子邮件后页面刷新,数据库也更新为mysql :-)。 But the issue is ,When i refresh the page after submitting the email ,i'm getting an conform form resubmission dialog .If i click continue button the same email (dublicate) is updating in new record.my db is updating with same email address when the i refresh page. 但问题是,当我在提交电子邮件后刷新页面时,我正在获得一个符合表格的重新提交对话框。如果我点击继续按钮,同一个电子邮件(dublicate)正在更新新记录。我的数据库正在使用相同的电子邮件地址进行更新当我刷新页面。 How to disable this message and stop updating the same duplicate records in mysql. 如何禁用此消息并停止更新mysql中的相同重复记录。

<form id="myForm" action="" onsubmit="return validateForm();"method="post">
    <input type="hidden" name="action" value="update" />
    <input type="text" name="email" id="email" value="Enter your email here" onfocus="if (this.value == 'Enter your email here') {this.value = '';}" onblur="if   (this.value == '') {this.value = 'Enter your email here';}" onwebkitspeechchange = "this.value = this.value.replace('Enter your email here','')" style=" margin:0px 0px 0px 26px;color:#999; border:4px solid #bbb;border-radius:6px;font-size:1em;width:260px;height:30px; font-style:italic; font-family:"Times New  Roman", Times, serif;"/>
    <br>
    <center>
        <input class="button" type="image" src="rss.png" />
    </center>
</form>
<?php
    $email = $_POST['email'];
    mysql_connect ("localhost", "root", "") or die ('Error: ' . mysql_error());
    mysql_select_db ("test"); 
    $query="INSERT INTO newsletter_emails (email)VALUES ('".$email."')";
    mysql_query($query) or die ('Error updating database');
?>
<script>
function validateForm() {
    var x = document.forms["myForm"]["email"].value;
    var atpos = x.indexOf("@");
    var dotpos = x.lastIndexOf(".");
    if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length) {
        alert("Not a valid e-mail address");
        return false;
    } else {
        alert("thankyou");
    }
}
</script>

When you submit a form, do a standard redirect afterwards. 提交表单时,请在之后执行标准重定向。 That way no POST info will be sent with the redirect. 这样,重定向就不会发送POST信息。 If you need to store things like an error message, use sessions. 如果您需要存储错误消息之类的内容,请使用会话。

Either; 无论;

  • transfer to a different page 转移到另一页

  • insert using AJAX and inform the user with AJAX 使用AJAX插入并使用AJAX通知用户

  • Create some kind of check to determine if the form is already posted (does the submit button contain a value for example) 创建某种检查以确定表单是否已发布(例如,提交按钮是否包含值)

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

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