如何保存表单数据,即使在提交后也不分散


How to keep form data even after submiting not to 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>

提交表单后,页面刷新,输入文本中的数据变为空白

是否可以在提交后保留数据?

谨致问候。

您可以简单地使用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>

尝试echo,以您的输入命名的变量是什么。

<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>

以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>

如果你在同一页面上处理帖子,你可以在你想要显示发布值的字段上这样做:

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

使用此:

<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>

基本上http是无状态协议,因此您需要将数据保存在

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

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