刷新页面后如何记住表格中的输入数据? [英] how to remember input data in the forms even after refresh page?
本文介绍了刷新页面后如何记住表格中的输入数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为了使表单即使在刷新页面后仍能记住用户的先前输入或当前输入,该怎么做?
what to do in order to make the form remember the previous input or the current input of the user even after he/she refreshed the page ?
我应该这样做,
<div class="row">
<label>Contact Messenger </label>
<input type="text" name="messenger" id="messenger" size="50" maxlength="50" value="<?php echo $_SESSION['messenger']; ?>"/>
</div>
或
<div class="row">
<label>Contact Messenger </label>
<input type="text" name="messenger" id="messenger" size="50" maxlength="50" value="<?php echo $_POST['messenger']; ?>"/>
</div>
或
有一个窍门吗?..如何?
there's a trick to do it ?..how ?
推荐答案
在您提交表单的页面上执行类似的操作
on the page where your form is submitting do something like this
session_start();
$_SESSION['data'] = $_POST['data'];
$_SESSION['data_another'] = $_POST['data_another'];
然后您可以在任何这样的位置访问这些会话变量
and than you can access those session variables any where like this
session_start(); // this should be at the top of the page before any html load
<input type="text" name="name" value="<?php echo $_SESSION['data'];?>"/>
在成功调用后刷新您的页面
refresh your page on success call like this
$.ajax({
type: "POST",
url: "yourfile.php",
data: 'data='+ data,
success: function(){
location.reload();
}
});
这篇关于刷新页面后如何记住表格中的输入数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文