Jump to content

[SOLVED] Images instead of Submit button


marmite

Recommended Posts

So, the form doesn't realise it's been submitted when I use an image... any ideas why? According to my Googling, you just use "image" instead of "submit" as type...

 

_____________________________________________________________________________________________________

 

IMAGE INSTEAD OF BUTTON - DOESN'T POST

FORM CODE

<form action="/cart.php" method="post" id="mycart">
<td><input name="qty" type="text" id="qty" size="3" /></td>
<td><input type="image" src="/images/cart.gif" id="submit5" name="submit5"></td>
</form>

 

PHP CODE - always generates 222 after submitting form (i.e. form not POSTed)

if ($_POST['submit5']) {
$_SESSION['test']="abc";
} else {
$_SESSION['test']="222";
}

_____________________________________________________________________________________________

 

NORMAL SUBMIT BUTTON - DOES POST

FORM CODE

<form action="/cart.php" method="post" id="mycart">
<td id="normal"><input name="qty" type="text" id="qty" size="3" /></td>
<td id="normal"><input type="image" src="/images/cart.gif" id="submit5" name="submit5"></td>
</form>

 

PHP CODE - always generates abc to say form has been POSTed

if ($_POST['submit5']) {
$_SESSION['test']="abc";
} else {
$_SESSION['test']="222";
}

__________________________________________________________________________________________________

Link to comment
https://forums.phpfreaks.com/topic/48424-solved-images-instead-of-submit-button/
Share on other sites

avoid it! safari and camino don't render the image inputs - instead they put a mac glass button there with no text on it.

 

FF and IE are different in how they send information on the submision of the image input - so you have to code for both - very dull.

 

Stick to using submit buttons and STYLE them (note same browsers don't style buttons very well BUT you can do something about that)

Just for the record - again - when you use an image as a submit, the html standard is to pass the x and y coordinate values of where you clicked relative to the upper left corner of the image. Why? Because that's how image maps work.

 

php allows you to retrieve those x and y values.  For example, if the NAME of your submit field is 'submit', then $_POST['submit_x'] and $_POST['submit_y'] will contain the values and $_POST['submit'] doesn't exist.

 

So, for the original poster, try checking for $_POST['submit5_x'] instead and you'll be fine.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.