PHP Form Handling
Language: PHP
<?php $errors = []; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = trim($_POST['name'] ?? ''); $email = trim($_POST['email'] ?? ''); if ($name === '') { $errors['name'] = 'Please enter your name.'; } if ($email === '') { $errors['email'] = 'Please enter your email.'; } if (empty($errors)) { echo 'All good, saving the record.'; } } foreach ($errors as $message) { echo '<p style="color:red">' . htmlspecialchars($message) . '</p>'; } ?>
Output
Click Run to execute this code.