I'm trying to implement a simple multi-language form in HTML. The form has buttons that open database tables in a div, and also has a select to choose the language.
The buttons are like:
<button type='submit' name='table' value='x'>
The select is like:
<select name='lang' onchange='changeLang()'>
...
function changeLang() {
document.getElementById('form1').submit();
}
When I click a button, it shows the table (and a parameter like 'table=x' shows in the URL). But when I change the language, only the 'lang=y' parameter shows, the 'table' parameter disappears.
I tried the solutions here, here and here, but it's not working. The hidden parameters add to the existing button and I get two 'table' parameters on the URL. How can I keep all the parameters on the URL without duplicating them?
EDIT: I was trying to do something on this 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>"; # only shows the button if not yet pressed
} else {
echo "<input type='hidden' name='table' value='$table' />"; # if pressed keep the variable (but is 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 the variable (but is doubling it?)
$table = NULL;
}
echo "<input type='text' name='msg' />";
echo "<input type='submit' value='ok' />";
$dir1 = glob('./coisas_txt*'); # all languages available as simple txt (key=value)
echo "<div id='langs' class='langs'>"; # class to make the language bar float
echo "<select name='lang' onchange='changeLang()'>";
foreach ($dir1 as $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'> <!-- where the table goes -->
<?php
if ($table !== NULL) {
}
?>
</div>
</form>
</body>
</html>