How can you display a message immediately after clicking the submit button on a PHP form?

To display a message immediately after clicking the submit button on a PHP form, you can use JavaScript to show an alert message or dynamically update the content of a specific HTML element. This can be achieved by adding an onclick event handler to the submit button that triggers the message display function.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Process form data here
    
    // Display a message after form submission
    echo "<script>alert('Form submitted successfully!');</script>";
}
?>

<form method="post">
    <!-- Form fields go here -->
    <input type="submit" name="submit" value="Submit" onclick="showMessage()">
</form>

<script>
function showMessage() {
    alert('Form submitted successfully!');
}
</script>