如何清除表单数据以便刷新不会在没有转发的情况下重复数据? [英] How to clear form data so refresh doesn't duplicate data without forwarding?

查看:94
本文介绍了如何清除表单数据以便刷新不会在没有转发的情况下重复数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个留言簿,用户可以通过HTML表单添加条目。将数据提交到留言簿后,一些用户刷新页面。我知道的所有浏览器都会重新提交数据。之后。有没有办法告诉浏览器,数据不应该重新提交?

I created a guestbook, in which users can add entries via an HTML form. After submitting data to the guestbook, some users refresh the page. All browsers I know resubmit the data. afterwards. Is there a way to tell the browser, that the data should not be resubmitted?

我以前有成功将数据存入数据库之后的重定向。但是,现在我想向用户提供一些附加信息,例如感谢您的参赛作品......。或者参赛作品中的一小部分已发送到您的电子邮件地址......。我真的很喜欢避免将所有值添加到GET参数以便能够在转发后使用这些信息。

I used to have a redirect after sucessfully storig the data to the database. But, now I want to promt some additional information to the user, e.g. "Thanks for your entry entitled '...'.", or "A coy of the entry was sent to your e-Mail-Adress...". I really like to avoid adding all the values to GET-Parameters to be able to use the information after the forwarding.

是否有另一种方式(没有前进!)到prevnt浏览器在用户点击刷新按钮后再次提交数据?

Is there another way (without a forward!) to prevnt the browser from submitting the data again after the user click on the "refresh" button?

推荐答案

也许你可以设置会话使用发布数据的哈希变量,并在每次加载页面时检查它。如果哈希值相同,则数据已经提交:

Maybe you could set a session variable with a hash of the data posted and check it each time the page is loaded. If the hash is the same, the data has already been submitted:

<?php
session_start(); //Start the session

$dataHash = md5($_POST['name'].$_POST['comment'].$_POST['whatever']); //Get a hash of the submitted data

if(isset($_SESSION['gbHash']) && $_SESSION['gbHash'] == $dataHash) { //Check if the data has been submitted before
    //Do not save the data/show a warning message
} else {
    //Save the data/show a thank you message
}


$_SESSION['gbHash'] = $dataHash;
?>

这篇关于如何清除表单数据以便刷新不会在没有转发的情况下重复数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆