views:

157

answers:

2

I have a website with a flag. If it is clicked, the language of the website changes.

Here is the code displaying the flag, which is a form with post event:

   <?php 
    $pagename = $_SERVER['REQUEST_URI'];
    echo '<form action="'.$pagename.'" method="post">
    <input name="formlanguage" type="image" ';
    if ($_SESSION['lang'] == 0)
    {
        echo 'alt="English" src="images/en.png" value="1" ';
    }
    else
    {
        echo 'alt="Deutsch" src="images/de.png" value="0" ';
    }
    echo '/></form>';
    ?>  

Here is the response to that, and this part always fails on IE:

if (isset($_POST['formlanguage']))
{
    $_SESSION['lang']=$_POST['formlanguage'];
}

I can not figure out why it works on Chrome but not IE. I assume that it might be a setting of IE. But what could that be?

+6  A: 

IE doesn't send the value for server side image maps, only the coordinates.

Since you have a simple toggle: add a hidden input which specifies the language to change to instead of depending on the image input data.

If you want to provide multiple options (or make it easier to do so in future), use different control names for different languages and check for the presence of each one (or rather, the name.x or name.y (with . converted to _ in PHP)) instead of having a standard name with different values.

David Dorward
This worked. Thank you.
Michael Frey
+1: nice to know that :)
Sarfraz
A: 

to be safe use hidden field for tracking language:

 echo '<form action="'.$pagename.'" method="post">';
 echo '<input id="lang" type="hidden" name="lang" value="'.$_SESSION['lang'].'" />';
 echo '<input name="formlanguage" type="image" onclick="setLanguage(this.value);" ';
 ....
 echo '<script>function setLanguage(l){ document.getElementbyId("lang").value=l;}</script>';

 ...

 if (isset($_POST['lang']))
 {
    $_SESSION['lang']=$_POST['lang'];
 }
jerjer