0

In my form, When i enter a false input like lesser than 4 letters in username or password, The page refreshes and all the data values are removed, Is there a possible way to keep the values? Since i don't want the use to retype all the inputs again just because he mistaken 1 input

<?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>
Calibur Victorious
  • 638
  • 1
  • 6
  • 20

0 Answers0