I want to have three languages in a website - two buttons for the non-selected language, and just a text for the used language - plus two buttons that shows different data on a div (tables from a database, not shown here).
Everything is "button type='submit'...". I read that I "just need to" add a "input type='hidden'...", but I get a repeated 'lang' parameter on the URL, because of the clickable buttons for the languages not selected.
What's the right way to do this, please?
Here's the code, with the floating language bar on the upper right corner:
<?php session_start();
// connects to the databse
$erroConn = include(".../connector.php");
// converts $_GETs to $php_vars
if (isset($_GET['lang'])) { // language
$lang = $_GET['lang'];
leDic($lang); // reads the apropriate language file
} else {
$lang = NULL;
}
if (isset($_GET['table'])) { // table
$table = $_GET['table'];
} else {
$table = NULL;
}
?>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>Example</title>
<style>
.langs { /* makes the language bar float */
background-color: #90A090;
position:absolute;
right:10;
top:10;
font-size: 0.75em; /* 10px/16px = 0.625em */
}
</style>
</head>
<body>
<form id="form1" name="form1" method="get" action="">
<?php
echo "<h1>".txt('titulo')."</h1>"; // draws the appropriate phrase from the language file
// if don't have a table selected yet
if (is_null($table)) {
// shows both buttons
echo "<button type='submit' name='table' value='A'>table A</button><BR>";
echo "<button type='submit' name='table' value='B'>table B</button><BR>";
} else {
// if already have a table selected, shows only the others as buttons
switch($table) {
case 'A':
echo "table A<BR>";
echo "<button type='submit' name='table' value='B'>table B</button><BR>";
break;
case 'B':
echo "<button type='submit' name='table' value='A'>table A</button><BR>";
echo "table B<BR>";
break;
}
}
// constructs the language bar inside the div 'langs'
$dir1 = glob('./coisas_txt*'); # all languages available
echo "<div id='langs' class='langs'>";
foreach ($dir1 as $fname) {
$sigla = mb_substr($fname,-2,NULL,'UTF-8');
// draws a darker button for the selected language
if ($sigla == $lang) {
echo "<button type='submit' name='lang' value='$sigla'><strong>$sigla</strong></button>";
} else {
echo "<button type='submit' name='lang' value='$sigla'>$sigla</button>";
}
}
echo "</div>";
echo "<div id='tabela'>";
if (!is_null($table)) {
// shows the data, if any
switch($table) {
case 'A':
echo 'tabela A';
break;
case 'B':
echo 'tabela B';
break;
}
}
echo "</div>";
?>
</form>
</body>
</html>
Thank you!