Validation means checking whether the data a user enters matches the format you expect. You need to check things like whether required fields are filled, whether the email format is correct, whether the password is long enough, or whether numbers fall within range — and do it reliably on the server side.
php
<?php
$name = "";
$email = "";
$errors = [];
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$name = trim($_POST["name"] ?? "");
$email = trim($_POST["email"] ?? "");
if ($name === "") {
$errors[] = "Name is required.";
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = "Please enter a valid email address.";
}
if (empty($errors)) {
echo "Form is valid.";
} else {
foreach ($errors as $error) {
echo htmlspecialchars($error) . "<br>";
}
}
}
?>You should see
If the input is valid, you'll see Form is valid. If not, error messages will appear.