How can a PHP form be set up to display a data verification page before sending the form?

To set up a PHP form to display a data verification page before sending the form, you can create a form with input fields for user data. Upon submission, the data is passed to a verification page where the user can review and confirm the information before final submission. This can help prevent errors and ensure accurate data submission.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Process form data and store in variables
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];

    // Display verification page
    echo "<h2>Review Your Information</h2>";
    echo "Name: " . $name . "<br>";
    echo "Email: " . $email . "<br>";
    echo "Message: " . $message . "<br>";

    // Add a submit button to confirm data
    echo "<form method='post' action='process_form.php'>";
    echo "<input type='hidden' name='name' value='" . $name . "'>";
    echo "<input type='hidden' name='email' value='" . $email . "'>";
    echo "<input type='hidden' name='message' value='" . $message . "'>";
    echo "<input type='submit' value='Confirm'>";
    echo "</form>";
} else {
    // Display form for user input
    echo "<form method='post' action='verification_page.php'>";
    echo "Name: <input type='text' name='name'><br>";
    echo "Email: <input type='email' name='email'><br>";
    echo "Message: <textarea name='message'></textarea><br>";
    echo "<input type='submit' value='Submit'>";
    echo "</form>";
}
?>