-2
I implemented this script, language exchange (or unit exchange, in this case):
/*Aqui ele coleta a seleção*/
$('#unidade').on('change', function() {
document.getElementById('form_unidade').submit();
});
<!-- Aqui se seleciona a unidade -->
<form method='get' action='' id='form_unidade' >
<select name='unidade' id="unidade" >
<option value='cidade-1' <?php if(isset($_SESSION['unidade']) && $_SESSION['unidade'] == 'cidade-1'){ echo "selected"; } ?> >São José do Rio Pardo</option>
<option value='cidade-2' <?php if(isset($_SESSION['unidade']) && $_SESSION['unidade'] == 'cidade-2'){ echo "selected"; } ?> >Mococa</option>
</select>
</form>
<!-- Ele aqui ele grava na sessão a unidade selecionada -->
<?php
if(isset($_GET['unidade']) && !empty($_GET['unidade'])){
$_SESSION['unidade'] = $_GET['unidade'];
if(isset($_SESSION['unidade']) && $_SESSION['unidade'] != $_GET['unidade']){
echo "<script type='text/javascript'> location.reload(); </script>";
}
}
if(isset($_SESSION['unidade'])){
include "php/multi-unidades/unidade_".$_SESSION['unidade'].".php";
}else{
include "php/multi-unidades/cidade-1.php";
}
if(!isset($_SESSION['unidade'])){
$unidade = "sao-jose-do-rio-pardo";
}else{
$unidade = $_SESSION['unidade'];
}
?>
It works perfectly for the occasion. If you could improve a detail, the link it generates is like this:
http://localhost/site/contact? unit=city-1
There are some pages that this causes problems.
In this structure, it would be possible for the generated link to have a bar before the query?
This does not answer the question. When you have reputation enough, you’ll be able to leave comments on any post but until then, write only answer that no depend on more information of who asked. - Of Revision
– Luiz Augusto
So answer the boy’s question please, he needs help. If my help isn’t enough, then help him, it would be more useful than scolding me for trying to help.
– Jean Carlos
Jean, no one is scolding, just you do not understand the purpose of Sopt. I recommend reading: Tour , How to create a Minimum, Complete and Verifiable example , Stack Overflow Survival Guide in English.
– Luiz Augusto
I tried to use window.location.href, but it was the same way. I think the problem is in the line "Document.getElementById('form_unit'). Submit();". An option I had tried, unsuccessfully and adjust the . htaccess to put a bar at the end of all url.
– Rogério Pancini