ell*_*one 1 html php forms jquery
<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>
Run Code Online (Sandbox Code Playgroud)
如何保持输入的值Name of drive
,Vehicle reg
并Haulier
在按下提交按钮后保持在那里?我想要这样,所以不必连续输入.我的表单已经作为一个动作去了,所以我可以$_POST
在这个页面上使用?
您需要做的就是检查该输入的值是否已被POST
编辑,如果有,则查看echo
该值.
为此,请在val
属性中添加:
<?php if(isset($_POST["name_of_input"])) echo $_POST["name_of_input"]; ?>
Run Code Online (Sandbox Code Playgroud)
......或使用三元运算符:
<?php echo(isset($_POST["name_of_input"]) ? $_POST["name_of_input"] : ""); ?>
Run Code Online (Sandbox Code Playgroud)
使用输出也是一种好习惯,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"]) : ""); ?>">
Run Code Online (Sandbox Code Playgroud)