Page 1 of 1

Using $_POST with an image as the submit button

Posted: Tue Apr 15, 2003 6:14 am
by r337ard
[admin edit: moved from the register_globals sticky thread]

i have read thru this a few times, but am still having problems using both post and get methods.

neither method seems to work when the input type is image. or mabey im just doing something wrong.

Code: Select all

<?
if (!empty($_REQUEST&#1111;'Home']))
&#123;$Home = 'ok';&#125; else &#123;$Home = 'nope';&#125;;
?>

<form action="test.php" method="get">
<input type="image" name="Home" src="button_home.gif" value="Home">
</form>

<?
echo "home = $Home<br>";
?>
now this code works in mozilla / phoenix. when you click the home button, it changes the home = nope to home = ok. however in IE it doesn't work. the reason is the value of each button isn't passed for some reason in IE.

mozilla url = http://www.garagelan.com/test/test.php? ... &Home=Home
IE url =
http://www.garagelan.com/test/test.php? ... &Home.y=13

two questions:
why is it passing x.y coordinates in the url?
and why doesn't IE pass the value of the input?

im stumped, any help would be muchly appreciated. i have tried using $_REQUEST $_POST and $_GET along with post and get method forms.. all have the same result.

thx

Posted: Tue Apr 15, 2003 6:49 am
by twigletmac
It passes x and y coordinates because you are using an image as a submit button and that information may be of interest to you - eg. you could have an image map type setup for your submit button - clicking on different areas could result in different actions. As for your second question - IE is IE, not sure why it does it this way but you'll end up having to work around it.

One way could be a hidden field, so that you have:

Code: Select all

&lt;form action="test.php" method="get"&gt; 
&lt;input type="hidden" name="action" value="post"&gt;
&lt;input type="image" name="Home" src="button_home.gif" value="Home"&gt; 
&lt;/form&gt;
and then you can do

Code: Select all

if (!empty($_GET['action']) && $_GET['action'] == 'post') {
    $Home = 'ok';
} else {
    $Home = 'nope';
}
// and
echo 'home = '.$Home.'<br />';
Mac

Posted: Tue Apr 15, 2003 6:54 am
by twigletmac
Of course you could also do:

Code: Select all

if (isset($_GET['Home_x']) && isset($_GET['Home_y'])) { 
    $Home = 'ok'; 
} else { 
    $Home = 'nope'; 
}
Mac