<form action='checks.php' method='POST'>
<div class ="bookinform">
<table>
<tr>
<td>Name of Driver *</td>
<td>
<input type='Text' id="driver_name" name='driver_name' required autocomplete="off" size='7' maxlength='25' style='width:400px;font-family:Century Gothic' value = "">
</td>
</tr>
<tr>
<td> </td>
<td></td>
</tr>
<tr>
<td>Vehicle Reg *</td>
<td>
<input type='Text' id="Vehicle_Reg" name='Vehicle_Reg' required autocomplete="off" size='7' maxlength='15' style='width:400px;font-family:Century Gothic; text-transform:uppercase;' value = "">
</td>
</tr>
<tr>
<td> </td>
<td></td>
</tr>
<tr>
<td valign='top'>Haulier *</td>
<td valign='top'>
<input type='Text' id="query" name='haulier' style='width:400px; font-family:Century Gothic; text-transform:uppercase;' value = "">
<tr>
<td> </td>
<td></td>
</tr>
</table>
<input type='submit' name='FORM' value="Book-in Piece/s" style='width:100%;font-family:Century Gothic; margin-top:10px; color:#2EFE2E;'>
</form>
如何在按下提交按钮后保留输入到Name of drive
、Vehicle reg
和Haulier
中的值?我想要这个,这样就不必连续输入它们。我的表单已经作为操作转到其他地方,以便我可以在此页面上使用$_POST
?
您
需要做的就是检查该输入的值是否已POST
,如果有,则echo
该值。
为此,请在 val
属性中添加:
<?php if(isset($_POST["name_of_input"])) echo $_POST["name_of_input"]; ?>
。或使用三元运算符:
<?php echo(isset($_POST["name_of_input"]) ? $_POST["name_of_input"] : ""); ?>
使用 htmlspecialchars()
输出也是一种很好的做法,因为某些POST
内容可能包含无效的 HTML。
完整示例
<input type='Text'
id="driver_name"
name='driver_name'
required
autocomplete="off"
size='7'
maxlength='25'
style='width:400px;font-family:Century Gothic'
value="<?php echo (isset($_POST["driver_name"]) ? htmlspecialchars($_POST["driver_name"]) : ""); ?>">
提交后可以通过以下方式维护该值:
<input type='Text' id="driver_name" name='driver_name' required autocomplete="off" size='7' maxlength='25' style='width:400px;font-family:Century Gothic' value = "<?php echo isset($_POST['driver_name']) ? $_POST['driver_name'] : NULL ?>">