How can the PHP code be modified to display all validation errors for multiple form fields in a more organized manner?
To display all validation errors for multiple form fields in a more organized manner, you can store each error message in an array and then loop through the array to display them. This way, all errors will be shown together in a clear and organized format.
$errors = array();
// Validate each form field
if(empty($_POST['name'])){
$errors[] = "Name is required";
}
if(empty($_POST['email'])){
$errors[] = "Email is required";
}
// Display errors
if(!empty($errors)){
echo "<ul>";
foreach($errors as $error){
echo "<li>$error</li>";
}
echo "</ul>";
}