How can the PHP code be modified to improve the overall user experience of the guestbook feature on the website?

Issue: The guestbook feature currently does not have any form validation, leading to potential spam submissions or incorrect data being entered. To improve the user experience, we can add form validation to ensure that only valid entries are submitted. PHP Code:

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $name = $_POST["name"];
    $message = $_POST["message"];
    
    // Validate form inputs
    if (empty($name) || empty($message)) {
        echo "Please fill out all fields.";
    } else {
        // Process and save the guestbook entry
        $entry = "Name: $name\nMessage: $message\n\n";
        file_put_contents("guestbook.txt", $entry, FILE_APPEND);
        echo "Entry submitted successfully!";
    }
}
?>

<form method="post" action="">
    <label for="name">Name:</label><br>
    <input type="text" id="name" name="name"><br>
    
    <label for="message">Message:</label><br>
    <textarea id="message" name="message"></textarea><br>
    
    <input type="submit" value="Submit">
</form>