I need to store the result of the html5 dropdown menu into a variable and use it with PHP. To simplify, I have a dropdown with 2 language selections. When I select one language, the result should be stored in a variable. Later on PHP will use that variable to show the correct language.
Currently I have set the variable directly in the code. See line 27 [$lang = "se";].
Any straightforward way to do pass the variable from html5 to PHP? Below is my code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div class="wrapper">
<!--HTML form (start)-->
<div class="lang-sel">
<form action="/action_page.php">
<select name="cars">
<option id="en" value="en">English</option>
<option id="se" value="se">Swedish</option>
</select>
</form>
</div>
<!--HTML form (end)-->
<!--PHP - language selector (start)-->
<?php
$lang = "se"; /*set variable*/
if ($lang =="en") {
echo "language set to english";
/* include 'content-en.html';*/
} else if ($lang =="se")
{
echo "language set to swedish";
/*include 'content-sv.html';*/
} else {
echo "You did not set lang to either english nor swedish";
}
?>
<!--PHP - language selector (end)-->
</div>
</body>
</html>