<?php session_start(); ?> <html> <head> <title>Form Validation</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous"></link> </head> <body> <div class="container"> <h2>Form Validation</h2> <!-- Disply required fields --> <?php if (array_key_exists('missingFields', $_SESSION) && count ($_SESSION['missingFields']) >0) { ?> <div class="alert alert-danger"> <p> The following field(s) are required:</p> <ul> <?php foreach($_SESSION['missingFields']as $field){?> <li><?php echo $field;?></li> <?php }?> </ul> </div> <?php $_SESSION['missingFields']=[]; $name=$_SESSION['name']; $age=$_SESSION['age']; $username=$_SESSION['username']; }?> <!-- Disply error messages--> <?php if (array_key_exists('errorMessage', $_SESSION) && count ($_SESSION['errorMessage']) >0) { ?> <div class="alert alert-danger"> <p> Form errors:</p> <ul> <?php foreach($_SESSION['errorMessage']as $message){?> <li><?php echo $message;?></li> <?php }?> </ul> </div> <?php $_SESSION['errorMessage']=[]; $name=$_SESSION['name']; $age=$_SESSION['age']; $username=$_SESSION['username']; } ?> <form action="script/script.php"method="post"> <div class="form-group"> <label for="name">Name:</label> <input type="text" name="name" id="name" class="form-control" value="<?php echo($name);?>"> </div> <div class="form-group"> <label for="age">Age:</label> <input type="text" name="age" id"age" class="form-control" value="<?php echo($age);?>"> </div> <div class="form-group"> <label for="gender">Gender:</label><br> <label> <input name="gender" type="radio" value="m" >Male</label> <label> <input name="gender" type="radio" value="f" >Female</label> <label> <input name="gender" type="radio" value="o" >Other</label> </div> <div class="form-group"> <label for="name">User Name:</label> <input type="text" name="username" id="username" class="form-control" value="<?php echo($username);?>"> </div> <div class="form-group"> <label for="name">Password:</label> <input type="password" name="password" id="password" class="form-control"> </div> <div class="form-group"> <input name="submit" type="submit" class="btn btn-primary" value="Submit Form"> </div> </form> </div> </body> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)