I have problems with setting a cookie in variable - I have to make it by PHP not JS because I need this variable on another subpages to change content of pages and display products and product variations depend on city choise, but this is not a content of this problem.
The problem is that i can't figure out how to make this variable by sending a form. I tried with below code but it doesn't work.
First solution:
if(isset($_POST['submit'])){
$city = htmlentities($_POST['city']);
setcookie('city', $city, time()+600);
}
Second:
if (isset($_POST['Madrid'])) {
$city = htmlentities($_POST['city']);
setcookie('city', $city, time()+600);
} else if (isset($_POST['London'])) {
$city = htmlentities($_POST['city']);
setcookie('city', $city, time()+600);
} else if (isset($_POST['Paris'])) {
$city = htmlentities($_POST['city']);
setcookie('city', $city, time()+600);
}
Form:
<form method="post" action="">
<input name='city' type="submit" value='Madrid'>
<input name='city' type="submit" value='London'>
<input name='city' type="submit" value='Paris'>
</form>