...

View Full Version : Cant get image to work as submit button



cornnfedd
01-17-2008, 11:02 AM
ive been pulling my hair out trying to get this simple script to work by using an image instead of the standard submit button, nothing i do will fix this!! when i hit submit on the image all it does it re-load the page. But when i use a standard submit button it works fine:

my code as follows (file named step2.php)

Initiation code helps direct you to the correct page depending on what you choose (i have blanked URL with ##)


<?php
if($_POST['submit'])
{
$colour = $_POST['col'];
if($colour == "unlimited")
{
if($_POST['bonus'] == "1")
{
$url = "#####URL#####";
}
else
{
$url = "#####URL#####";
}
}
if($colour == "2year")
{
if($_POST['bonus'] == "1")
{
$url = "#####URL#####";
}
else
{
$url = "#####URL#####";
}
}
if($colour == "1year")
{
if($_POST['bonus'] == "1")
{
$url = "#####URL#####";
}
else
{
$url = "#####URL#####";
}
}
//echo $url;
header("Location: $url");
}
?>

form code here:

<form name="formColor" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<input type="radio" name="col" value="unlimited" checked/>choice1</td><td>
<a href="#" ONMOUSEOVER="popup(choice1','yellow')"; ONMOUSEOUT="kill()"><img src="images/question.gif" align="middle" border="0" width="18" height="18"></a>
</td></tr><tr><td align="left">
<input type="radio" name="col" value="2year" />choice 2</td><td>
<a href="#" ONMOUSEOVER="popup(choice2','yellow')"; ONMOUSEOUT="kill()"><img src="images/question.gif" align="middle" border="0" width="18" height="18"></a>
</td></tr><tr><td align="left">
<input type="radio" name="col" value="1year" />choice3</td><td>
<a href="#" ONMOUSEOVER="popup('choice3','yellow')"; ONMOUSEOUT="kill()"><img src="images/question.gif" align="middle" border="0" width="18" height="18"></a>
</td></tr><tr><td align="left">
<input name="bonus" type="checkbox" id="bonus" value="1" checked><font size="2" color="999999"> *give me bonus!</font>
</td></tr></table>
<input type="submit" name="submit" value="Proceed to Next Step" />
</form>
above works.

so if i replace the input line to try and get it to load with an image instead of a submit button i was using:


<input type="image" name="submit" src="images/justordernow.jpg" border="0" />


and all this does is reload the same page over and over.

can someone help me please!!!!!

mlse
01-17-2008, 12:17 PM
when you use <input type="image" name="foo" src="..." />, two callback variables are passed to the server, namely "foo_x" and "foo_y" - these contain the coordinates on the image of the mouse cursor when the click occurred - this is because <input type="image" ... /> actually creates an image map rather than a simple button. You could get round this by having a hidden variable in your form (with a known name and value) - that way you can change between <input type="submit" ... /> and type="image" without needing to modify your callback code.

ahallicks
01-17-2008, 01:15 PM
<input type="hidden" name="submitted" value="TRUE" />


Then:



if(isset($_POST['submitted']))

or

if($_POST['submitted'] == 'TRUE'){

o0O0o.o0O0o
01-18-2008, 04:03 AM
or

use hyperlink on the image

<a href =mmmm> ......image... </a>

o0O0o.o0O0o
01-18-2008, 04:05 AM
ive been pulling my hair out

By the way , how many hairs you have pulled :)

felgall
01-18-2008, 07:02 AM
When you use an image to submit it passes an array of two values (the X and Y coordinates of the mouse when it clicked the image) rather than a single value. Also if the submit is triggered from the keyboard both mouse coordinates will be zero (ie false).

ahallicks suggestion of a hidden field is the easiest fix.

cornnfedd
01-19-2008, 01:44 PM
ok so how do i add that into the webpage - sorry im pretty stupid and need my hand held!!!!!!!!!!!!!!!!!!!!

mlse
01-22-2008, 11:22 AM
Do it like this:

Update:


<form name="formColor" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<input type="radio" name="col" value="unlimited" checked/>choice1</td><td>
<a href="#" ONMOUSEOVER="popup(choice1','yellow')"; ONMOUSEOUT="kill()"><img src="images/question.gif" align="middle" border="0" width="18" height="18"></a>
</td></tr><tr><td align="left">
<input type="radio" name="col" value="2year" />choice 2</td><td>
<a href="#" ONMOUSEOVER="popup(choice2','yellow')"; ONMOUSEOUT="kill()"><img src="images/question.gif" align="middle" border="0" width="18" height="18"></a>
</td></tr><tr><td align="left">
<input type="radio" name="col" value="1year" />choice3</td><td>
<a href="#" ONMOUSEOVER="popup('choice3','yellow')"; ONMOUSEOUT="kill()"><img src="images/question.gif" align="middle" border="0" width="18" height="18"></a>
</td></tr><tr><td align="left">
<input name="bonus" type="checkbox" id="bonus" value="1" checked><font size="2" color="999999"> *give me bonus!</font>
</td></tr></table>

<!-- Here's the first change to your code -->
<input type="image" name="submit" src="images/justordernow.jpg" border="0" />
<input type="hidden" name="submitted" value="TRUE" />
<!-- --- -->

</form>


Callback:


if (isset($_POST['submitted'])) //Here's the second change.
{
$colour = $_POST['col'];
if($colour == "unlimited")
{
if($_POST['bonus'] == "1")
{
$url = "#####URL#####";
}
else
{
$url = "#####URL#####";
}
}
if($colour == "2year")
{
if($_POST['bonus'] == "1")
{
$url = "#####URL#####";
}
else
{
$url = "#####URL#####";
}
}
if($colour == "1year")
{
if($_POST['bonus'] == "1")
{
$url = "#####URL#####";
}
else
{
$url = "#####URL#####";
}
}
//echo $url;
header("Location: $url");
}

:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum