Create a select of cities, when to choose the city goes to the specific site of the chosen city

0

This is my select, I have tried to use it for a long time, I do not know how it works, I see that many great websites use it and the user selects the city, it shows the respective content, but the URL does not change.

<form action="cid.php" method="get">
    <select name="cidade" id="cidade">
        <option>Selecione</option>
        <option value="Cidade 1">Cidade 1</option>
        <option value="Cidade 2">Cidade 2</option>
        <option value="Cidade 3">Cidade 3</option>
    </select>
  <input type="submit" name="submit" id="submit" class="botao" value="Ok">
</form>

Who can help or give me a direction, thank you very much.

    
asked by anonymous 07.01.2018 / 23:12

1 answer

1

You can put the HTML like this:

<form action="cid.php" method="get">
    <select name="cidade" id="cidade">
        <option>Selecione</option>
        <option value="city1">Cidade 1</option>
        <option value="city2">Cidade 2</option>
        <option value="city3">Cidade 3</option>
    </select>
  <input type="submit" name="submit" id="submit" class="botao" value="Ok">
</form>

And in the code of the file cid.php , you can do a logic something like this:

<?php

    switch ($_GET['citade']) {
        case 'city1':
            header('Location: /cidade-1.php');
            exit;

        case 'city3':
            header('Location: /cidade-1.php');
            exit;

        case 'city3':
            header('Location: /cidade-1.php');
            exit;

        default:
            header('Location: /default.php');
            exit;
    }
    
08.01.2018 / 00:28