0

Why does submitting a form not work in sololearn's code playground?

I was trying to use a form and check the input using some php code, but when I would submit the form, the output section would return the screen that I was on and not what it was suppose to be outputting. This is the form and php: <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> Name: <input type="text" name="name"> <br><br> E-mail: <input type="text" name="email"> <br><br> Password: <input type="text" name="password"> <input type="submit" name="submit" value="Submit"> </form> <?php $name = $email = $password = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { echo "Name is required"; } else { if (!preg_match("/^[a-zA-Z ]*$/",$name)) { echo "Only letters and white space allowed"; } else{ $name = test_input($_POST["name"]); echo "Your name is " . $name; } } if (empty($_POST["email"])) { echo "Email is required"; } else { if (!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) { echo "Invalid email format"; } else{ echo "Welcome"; } } if (empty($_POST["password"])) { echo "Password is required"; } else { echo "Come on in"; } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?>

26th Jun 2019, 8:49 PM
Gunnarhawk
Gunnarhawk - avatar
1 Antwort
0
Because we can only write html ,css and js
19th May 2021, 5:52 AM
Ayush Kumar Mahto
Ayush Kumar Mahto - avatar