What are the best practices for handling language changes in PHP forms, especially when using cookies?

When handling language changes in PHP forms, especially when using cookies, it is best practice to store the selected language in a cookie and then use that cookie value to dynamically change the language of the form. This ensures that the selected language persists across different pages and sessions.

// Check if the language cookie is set
if(isset($_COOKIE['language'])){
    $language = $_COOKIE['language'];
} else {
    $language = 'en'; // Default language
}

// Use the selected language to display the form
if($language == 'en'){
    echo "English Form";
} elseif($language == 'fr'){
    echo "Formulaire en français";
} else {
    echo "Unsupported language";
}