Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

input type=image name and value not being sent by ie and opera

When a form has multiple image inputs and the server side uses their names and/or values to distinguish which one was clicked, it works perfectly in FireFox. However, people often write the whole thing before finding out that HTML specifies that nothing has to be sent, and thus some browsers are not sending it.

It's not about sending any random object, but sending a pair as input_name=input_value. The best worst-case scenario example here would be what I've encountered: A list of elements all in one form and all accompanied by buttons with name="delete" value="<item_id>"

What can I do to fix this problem?

like image 234
naugtur Avatar asked Dec 30 '25 19:12

naugtur


2 Answers

Per the HTML spec, clicking on an IMAGE input will return the parameters:

name.x=x-value and name.y=y-value where "name" is the value of the name attribute

with x-value and y-value corresponding to the click position.

Sure, the server code to deal with this will be a little annoying, but you could just check all the query parameter keys with a regular expression:

/^(.*)\.[xy]$/

to search for the IMAGE input keys to determine which IMAGE was clicked.

like image 87
Dancrumb Avatar answered Jan 01 '26 22:01

Dancrumb


I tried with this sample:

<form action="#" method="GET">
  <input type="text" name="t" value="Text here"><br>
  <input type="image" name="a" value="1" src="http://sstatic.net/so/img/logo.png"><br>
  <input type="image" name="b" value="2" src="http://www.gravatar.com/avatar/c541838c5795886fd1b264330b305a1d?s=32&d=identicon&r=PG"><br>
</form>

And I get the following urls:

  • FF 3.6: x.html?t=Text+here&b.x=19&b.y=17&b=2#
  • IE 8: x.html?t=Text+here&b.x=22&b.y=18
  • IE 7: x.html?t=Text+here&a.x=185&a.y=51
  • Opera 10: x.html?t=Text+here&a.x=107&a.y=53#
  • Chrome: x.html?t=Text+here&b.x=20&b.y=17&b=2#

So it seems that all the browsers are sending something image related, even if it isn't the image name directly. Since you need to scan for all the image names that you expect to see you can just scan for imagename.x instead. This seems to be how the spec indicates it should work.

like image 37
Mr. Shiny and New 安宇 Avatar answered Jan 01 '26 23:01

Mr. Shiny and New 安宇



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!