0
How can I make a form with a UF field and a selection field with label Cities that will be filled through AJAX and that when selecting the UF the JS function connects to the server and returns the cities of that UF, but without searching in the Database? I was directed to do with a switch-case structure or something similar that returns values from a key value, but I have no idea how it works. I just have an idea how to do using the database.
NOTE: I decided to do with the database, because I think it is more practical.
I already made the form:
<form name="formCadastro" action="buscaCidade.php" method="post">
<label>Nome</label>
<input type="text" name="name" placeholder="Digite seu nome" required>
<label>E-mail</label>
<input type="email" name="email" placeholder="Digite seu email">
<label>UF</label>
<select name="uf">
</select>
<label>Cidade</label>
<select name="cidade">
<!--INSERIR AQUI AS OPÇÕES DE CIDADE-->
</select>
<input type="submit" name="submit" value="Enviar">
</form>
And I also made the bank, which would be something like this:
DROP TABLE IF EXISTS `cidades`;
DROP TABLE IF EXISTS `estados`;
CREATE TABLE `cidades` (
`estados_cod_estados` int(11) DEFAULT NULL,
`cod_cidades` int(11) DEFAULT NULL,
`nome` varchar(72) COLLATE utf8_unicode_ci DEFAULT NULL,
`cep` varchar(8) COLLATE utf8_unicode_ci DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `estados` (
`cod_estados` int(11) DEFAULT NULL,
`sigla` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL,
`nome` varchar(72) COLLATE utf8_unicode_ci DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Now I’m finishing PHP.
What have you ever done?
– Paulo Santos
I made HTML, BD and now I’m finishing PHP.
– boomboxarcade