<?php $name = ''; $password = ''; $color = ''; $languages = array(); $comments = ''; if (isset($_POST['submit'])) { //echo htmlspecialchars($_POST['searchterm'], ENT_QUOTES); $ok = true; if (isset($_POST['submit'])) { if (!isset($_POST['name']) || empty($_POST['name'])) { die('Name is required'); } else { $name = $_POST['name']; } if (!isset($_POST['password']) || empty($_POST['password'])) { $ok = false; } else { $password = $_POST['password']; } if (isset($_POST['password'])) $password = $_POST['password']; if (isset($_POST['color'])) $color = $_POST['color']; if (isset($_POST['languages'])) $languages = $_POST['languages']; if (isset($_POST['comments'])) $comments = $_POST['comments']; } if ($ok) { printf('User name: %s<br>', htmlspecialchars($name, ENT_QUOTES)); printf('Password: %s<br>', htmlspecialchars($password, ENT_QUOTES)); printf('Favorite Color: %s<br>', htmlspecialchars($color, ENT_QUOTES)); printf('Languages Spoken: %s<br>', htmlspecialchars(implode(', ', $languages), ENT_QUOTES)); printf('Comments: %s<br>', htmlspecialchars($comments, ENT_QUOTES)); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="icon" type="image/x-icon" href="favicon.ico"> <link rel="stylesheet" href="form.css"> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap" rel="stylesheet"> </head> <body> <form action="" method="post"> <label for="name">User name</label> <input type="text" name="name" value="<?php echo htmlspecialchars($name, ENT_QUOTES); ?>"> <label for="password">Password</label> <input type="password" name="password"> <label for="color">Favorite Color</label> <select name="color" id="color"> <option value="">Please select...</option> <option value="#f00">Red</option> <option value="#0f0">Green</option> <option value="#00f">Blue</option> </select> <label for="languages">Languages Spoken</label> <select name="languages[]" id="languages" multiple="multiple"> <option value="en">English</option> <option value="fr">French</option> <option value="de">German</option> </select> <label for="comments">Comments</label> <textarea name="comments" id="comments" cols="30" rows="10"> <?php echo htmlspecialchars($comments, ENT_QUOTES); ?> </textarea> <input type="submit" name="submit" value="Register"> </form> </body> </html>