如果在php
页面刷新后,如何保留文本框的值提前致谢。
答案 0 :(得分:7)
示例1
<?php
session_start();
if (isset($_POST['submit'])) {
$_SESSION['test'] = $_POST['test'];
}
?>
<form method="post" action="">
<input type="text" value="<?php echo isset($_SESSION['test']) ? $_SESSION['test'] : ''; ?>" name="test" />
<input type="submit" value="submit" name="submit" />
</form>
示例2
<form method="post" action="">
<input type="text" value="<?php echo isset($_POST['test']) ? $_POST['test'] : ''; ?>" name="test" />
<input type="submit" value="submit" name="submit" />
</form>
答案 1 :(得分:1)
如果您想在页面提交后保留文本框中的数据,请在下面举例说明
<input type="text" name="sample" value="<?php (isset($_POST['sample']))?$_POST['sample']:''; ?>" />