What is a more elegant solution to handling form submissions and setting cookies in PHP?

When handling form submissions and setting cookies in PHP, a more elegant solution is to separate the logic for processing the form data and setting the cookies into different functions. This helps improve code readability and maintainability by breaking down the tasks into smaller, more manageable parts.

<?php

// Function to process form submission
function processFormSubmission() {
    // Check if form is submitted
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        // Process form data
        $formData = $_POST['formData'];
        
        // Call function to set cookies
        setCookies($formData);
    }
}

// Function to set cookies
function setCookies($data) {
    // Set cookies based on form data
    setcookie('cookieName', $data, time() + 3600, '/');
}

// Call function to process form submission
processFormSubmission();

?>