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
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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.