PDA

View Full Version : <input type='image'..> sends its value in FF but not IE?!



cfgovinda
Apr 25th, 2009, 02:10 AM
Hi,

I have this in a form:

<input name='ApplyCoupon' type='image' src='images/ApplyCoupon.gif' value=' Apply Coupon ' style="" />

On Mac/FF the page that the form posts to receives that incoming var's name/value pair. But on Vista/IE7 that name/value pair never shows up. I have a couple images that can submit the form. I need them each to pass their name/value on to the page we post to so that I can do different things depending on which button the user used to post.

Is there a trick to make the above <input type='image'> do the right thing in IE6-8?

thanks!
-Govinda

cfgovinda
Apr 25th, 2009, 03:24 AM
I figured out I can just use type="submit for that input, and style the graphic on with the background property..
Is that the way you would do it? Any advantage to using type="image"?
-G

cfgovinda
Apr 25th, 2009, 03:28 AM
yes, the advantage is that I want the value to be passed in the post, but I *don't* want that text for that value to sit on top of my button!!

So my question remains - how to get IE to let the input type="image" to pass its value?

CFMaBiSmAd
Apr 25th, 2009, 03:35 AM
The HTML specification only requires that x, y coordinates where the image submit button was clicked be sent to the web server. IE follows the specification. The browsers that send the value="..." parameter are doing their own thing outside of the HTML specification.

If you don't want to use the x, y coordinates where the image was clicked and really want a value to be sent, create a hidden field with a name and a value that you want to be sent when that form is submitted.

cfgovinda
Apr 25th, 2009, 03:41 AM
yes, OK, I understand. Thanks for explaining here where IE (for a change) is doing the expected thing. But I can't use a hidden field (that I am aware of) since regardless of which button the user user to post the form, that hidden field gets sent. I need to know which button the user used.

CFMaBiSmAd
Apr 25th, 2009, 03:52 AM
Then test which button was clicked by checking for one of the x/y coordinates - http://www.php.net/manual/en/faq.html.php#faq.html.form-image

cfgovinda
May 5th, 2009, 12:27 AM
unfortunately, in IE7 if the user uses his enter key instead of clicking the img input (submit) button, then we still don't get the var passed in (i.e. the 'name' of the img input is still undefined)! So I still don't have a reliable method of knowing which of a few img inputs the user used to submit his form (if he uses the enter key instead of clicking).

-Govinda

CFMaBiSmAd
May 5th, 2009, 12:29 AM
Already posted the solution to that problem -
If you don't want to use the x, y coordinates where the image was clicked and really want a value to be sent, create a hidden field with a name and a value that you want to be sent when that form is submitted.

cfgovinda
May 5th, 2009, 12:33 AM
yes, but your solution requires a hidden input.. which gets sent whether img input#1 or #2 is used. Thus how can I tell which of the two buttons the (IE) user meant to click when he instead just hit the enter key?

drhowarddrfine
May 5th, 2009, 02:17 PM
I don't know that the same problem exists for images in IE as it does for <button> but IE does not send the proper name/value pair in forms when there is more than one.

grodintampa
Sep 11th, 2010, 08:06 PM
I know this is an old post but thought I would share a solution I used...

I had 2 "image" buttons, one for credit card and one for Paypal.

I called them "cc" and "pp".

Since IE only takes the location values (in pixels) of which button you click I used this instead.

if($_POST[cc_x]>0) { do the credit card page }
elseif($_POST[pp_x]>0) {do the paypal page }

where cc_x is the x coordinate and cc_y is y coordinate
where pp_x is the x coodinate and pp_y is y coordinate

By just using >0 you'll know if ANY part of that button is clicked, do that page.

Hope this helps anyone else (like I did) who Googles for this answer. ;)

This works across all browsers and all of them "append" the _x and _y to your image variable name (cc becomes cc_x and cc_y for example)

bhaskarcse
Dec 26th, 2010, 02:33 PM
Even a better solution would be to just check if the variables cc_x and cc_y is set or pp_x and pp_y is set. Like as follows

if(isset($_POST[cc_x]) && isset($_POST[cc_y]))
{
//Do something
} elseif(isset($_POST[pp_x]) && isset($_POST[pp_y]))
{
//Do something
}


www.brahmaesolutions.com (http://www.brahmaesolutions.com/)