I try to make a language selection page but when submitting the ‘value’ parameter of id=”image” name=”image” doesn’t get passed, instead I get image_x and image_y values in $_POST..
This is my code:
session_start();
include("languages.php");
function lng($which)
{
global $ARRXKS;
return $ARRXKS[$_SESSION['lang']]["$which"];
}
function LangChoose()
{
echo('
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Meet-Helmond.nl SMS Service - Select your Language</title>
<link href="css.css" rel="stylesheet" type="text/css" />
</head>
<div class="information">
<div class="boxinfo">Cookies MUST be enabled to use this website!</div>
<p>
<form id="loginForm" name="loginForm" method="post" action="index.php">');
echo('<BR />');
print_r($_POST);
echo('<BR />');
global $ARRXKS;
$LANG_keys = array_keys($ARRXKS);
$count = 1;
for ($i = 0; $i <= count($ARRXKS) - 1; $i++)
{
echo('<input type="image" src="images/flags/'.$LANG_keys[$i].'.png" name="image" id="image" value="'.$LANG_keys[$i].'">');
if((($count) % 5) == 0)
{
echo('<BR />');
}
$count = $count + 1;
}
echo('
</form>
</div>
<body>
</body>
</html>
');
}
//print_r($_POST);
if(!isset($_SESSION['lang']))
{
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if(isset($_POST['image']))
{
if (array_key_exists($_POST['image'], $ARRXKS))
{
$_SESSION['lang'] = $_POST['image'];
}
else
{
LangChoose();
exit();
}
}
else
{
LangChoose();
exit();
}
}
else
{
LangChoose();
exit();
}
}
so when I retrieve it it doesn’t detect which language I chose, how can I correctly submit the value of the clicked image?
Images when submitted do not have any value. Instead the x and y coordinates in pixel are submitted by the browser. This is totally normal and the way how the image input element works.
Instead you might want to use submit buttons that have a graphic via their CSS style or the more modern button input element.
Use the HTML reference of your choice to clarify your understanding of the input image tag and to learn about the submit input and the button input.