What are the best practices for handling form submission validation in PHP to prevent multiple clicks for successful submission?

To prevent multiple form submissions in PHP, one common approach is to disable the submit button after it has been clicked to prevent users from clicking it multiple times. This can be achieved by using JavaScript to disable the button on click and also adding server-side validation to check if the form data has already been submitted.

<?php
session_start();

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (!isset($_SESSION['form_submitted'])) {
        // Process form data here
        
        // Set a session variable to mark form submission
        $_SESSION['form_submitted'] = true;
    } else {
        // Form has already been submitted, display an error message or redirect
        echo "Form has already been submitted.";
        exit;
    }
}
?>