php - How do I keep the parameters on the URL (HTML GET) without duplicating them? -
i'm trying implement simple multi-language form in html. form has buttons open database tables in div, , has select choose language.
the buttons like:
<button type='submit' name='table' value='x'>
the select like:
<select name='lang' onchange='changelang()'> ... function changelang() { document.getelementbyid('form1').submit(); }
when click button, shows table (and parameter 'table=x' shows in url). when change language, 'lang=y' parameter shows, 'table' parameter disappears.
i tried solutions here, here , here, it's not working. hidden parameters add existing button , 2 'table' parameters on url. how can keep parameters on url without duplicating them?
edit: trying on line:
<?php session_start(); $erroconn = include(".../dbfile.php"); if (isset($_get['lang'])) { // language $lang = $_get['lang']; ledic($lang); } else { $lang = null; } if (isset($_get['table'])) { // table $table = $_get['table']; } else { $table = null; } if (isset($_get['people'])) { // people $people = $_get['people']; } else { $people = null; } ?> <html lang='en'> <head> <meta charset='utf-8'> <title>example</title> <script type='text/javascript'> function changelang() { document.getelementbyid('form1').submit(); } </script> </head> <body> <form id="form1" name="form1" method="get" action=""> <h1>titulo</h1> <?php if (is_null($table)) { echo "<button type='submit' name='table' value='0'>tabelas</button>"; # shows button if not yet pressed } else { echo "<input type='hidden' name='table' value='$table' />"; # if pressed keep variable (but doubling it?) $people = null; } if (is_null($people)) { echo "<button type='submit' name='people' value='0'>people</button><br>"; } else { echo "<input type='hidden' name='people' value='$people' />"; # if pressed keep variable (but doubling it?) $table = null; } echo "<input type='text' name='msg' />"; echo "<input type='submit' value='ok' />"; $dir1 = glob('./coisas_txt*'); # languages available simple txt (key=value) echo "<div id='langs' class='langs'>"; # class make language bar float echo "<select name='lang' onchange='changelang()'>"; foreach ($dir1 $fname) { $sigla = mb_substr($fname,-2,null,'utf-8'); if ($sigla == $lang) { echo "<option value='$sigla' selected>$sigla</option>"; } else { echo "<option value='$sigla'>$sigla</option>"; } } ?> </select> </div> </div> <div id='table'> <!-- table goes --> <?php if ($table !== null) { } ?> </div> </form> </body> </html>
hidden fields should work.
for each table have form element hidden input tables unique id , select languages. example:
<form id="form1" name="form1"> <input type="hidden" id="table_1" name="table_1" value="x" /> <select id="lang" name='lang' onchange='changelang()'> </form> <form id="form2" name="form2"> <input type="hidden" id="table_2" name="table_2" value="x" /> <select id="lang" name='lang' onchange='changelang()'> </form>
and have changelang function submit form it's in only. native dom elements inputs have form attribute points form belong should work. find parent of input calls javascript function in javascript. might able use closest here well. play it.
function changelang() { var form = ______.form; form.submit(); }
then interpret $_get['table'] , $_get['lang'] variables using php decide show. so:
<?php //switch based on language... switch($_get['lang']){ case 'lang1': //display table_1 if should if($_get['table_1']){ ?> <!-- table_1 display in lang1 html here. --> <?php } //display table_2 if should if($_get['table_2']){ ?> <!-- table_2 display in lang1 html here. --> <?php } break; case 'lang2': //display table_1 if should if($_get['table_1']){ ?> <!-- table_1 display in lang2 html here. --> <?php } //display table_2 if should if($_get['table_2']){ ?> <!-- table_2 display in lang2 html here. --> <?php } break; default //display table_1 if should if($_get['table_1']){ ?> <!-- table_1 display in default lang html here. --> <?php } //display table_2 if should if($_get['table_2']){ ?> <!-- table_2 display in default lang html here. --> <?php } break; } ?>
something that.
hope helps!
Comments
Post a Comment