-1
I’m sending neighborhoods by $_GET through a form and would like to mark them dynamically in updating the screen thus making a system of persistence of the search results.
<fieldset class="normal">
<input type="checkbox" name="bairros[]" value="BELEM NOVO" id="BELEM NOVO">
<label for="BELEM NOVO">Belém Novo</label>
<input type="checkbox" name="bairros[]" value="BOM FIM" id="BOM FIM">
<label for="BOM FIM">Bom Fim</label>
<input type="checkbox" name="bairros[]" value="SANTA CLARA" id="SANTA CLARA">
<label for="SANTA CLARA">Santa Clara</label>
</fieldset>
I include the file bairros.php
shortly after the body with a require and capture all the neighborhoods that were marked on the form with $_GET on the return page.
# Persistencia dos bairros
$inbairros = $_GET["bairros"];
if(array_key_exists("bairros", $_GET)){
foreach($inbairros as $baitem => $bavalue) {
// select bairros
}
}
If I do echo $bavalue
within the foreach
, logically it returns me all the neighborhoods that were selected in the form. The value
input contains the same content.
Question: How to dynamically select returned neighborhoods and place checked
in all of them without having to treat one by one?
That’s on a search form and you want to keep those neighborhoods checked as you choose at the time of the search?
– Jorge B.
Marcos, do these neighborhoods.php files include your form? It needs to be generated dynamically or do you have to use Javascript.
– gmsantos
Jorge is a research form and I want to keep the fields checked after the Submit of it (persistence of the fields).
– Marcos Vinicius
Gmsantos, the
bairro.php
contains simply the foreach code added just after thebody
that sees if house Submit from the specific array and takes the data.– Marcos Vinicius