2014-09-22 50 views
0

在这种如何保持表单数据甚至submiting不dispear

<form method="POST" action=""> 
<input type="text" class="field small-field" name="tex1" /> 
<input type="submit" value="search" name="search"/> 
<input type="submit" value="print" name="print"/> 
</form> 

我提交表格后后,页面刷新,数据输入文本内获得空白

是否有可能保持数据提交后甚至?

问候。

+1

阿贾克斯的Heared ... :-) http://api.jquery.com/jquery.ajax/ – 2014-09-22 09:21:14

+0

有答案同一主题http://stackoverflow.com/questions/7014146/how-to -remember-input-data-in-the-forms-even-after-refresh-page – Maantje 2014-09-22 09:21:42

+0

@웃웃웃웃웃可能没有人听说过听过ajax的人。 – 2014-09-22 09:36:17

回答

1

尝试呼应

或使用,什么都被命名为您输入的变量。

<form method="POST" action=""> 
    <input type="text" class="field small-field" name="tex1" value="<?php echo $_POST['tex1'];?>" /> 
    <input type="submit" value="search" name="search"/> 
    <input type="submit" value="print" name="print"/> 
</form> 
1

用PHP例如:

<form method="POST" action=""> 
<input type="text" class="field small-field" name="tex1" value="<?php echo $_POST['tex1']; ?>"/> 
<input type="submit" value="search" name="search"/> 
<input type="submit" value="print" name="print"/> 
</form> 
+0

添加一个检查,如果该帖子已设置,或者如果没有帖子,它会回显一个未定义的变量。 – 2014-09-22 09:23:35

1

如果您正在处理在同一页上的帖子,你可以只是做这样你想上哪儿张贴值的字段中显示:

<input type="submit" value="search" name="search" <?php if(isset($_POST['search'])){ echo "value=\"". $_POST['search'] ."\"; } ?>/> 
1

使用此:

<form method="POST" action=""> 
    <input type="text" class="field small-field" name="tex1" value="<?php if(isset($_POST['tex1'])) echo $_POST['tex1'] ?>" /> 
    <input type="submit" value="search" name="search"/> 
    <input type="submit" value="print" name="print"/> 
</form> 
1

Bascially HTTP是statelessprotocol,因此你需要一些地方保存数据

在这种情况下,最简单的方法是使用一个条件运算符

<input type="text" class="field small-field" name="tex1" value="<?php echo (isset($_POST['search'] || $_POST['search'])?$_POST['tex1']:''); ?>" /> 
2

您可以简单地使用AJAX提交表单。以下

<form method="POST" action=""><input type="text" class="field small-field" name="tex1" value="<?php (isset($_POST['text1]))? echo $_POST['text1] : '';" /><input type="submit" value="search" name="search"/><input type="submit" value="print" name="print"/></form> 
相关问题