在我的表单中,当我在用户名或密码中输入少于4个字母的错误输入时,页面刷新并删除所有数据值,是否有可能保留值?因为我不想再次重新输入所有输入,因为他错误地输入了一个
<?php if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
if(!preg_match("/^[0-9a-zA-Z_]{4,}$/", $username) || empty($username)) {$uErr = "style='border: 2px solid red;'";}
elseif(!preg_match("/^.*(?=.{8,})$/", $password) || empty($password)) {$pErr = "style='border: 2px solid red;'";} else {
echo "Hello";}} ?>
<form action="" method="post">
<div class="form-group">
<label>Username:</label>
<input <?php if(isset($uErr)){echo $uErr;} ?> name="username" type="text" class="form-control">
</div>
<div class="form-group">
<label>Password:</label>
<input <?php if(isset($pErr)){echo $pErr;} ?> name="password" type="password" class="form-control">
<button name="submit" type="submit">Submit</button>
</div>
</form>