Input Type image submit form value?
I was in the same place as you, finally I found a neat answer :
<form action="xx/xx" method="POST">
<input type="hidden" name="what you want" value="what you want">
<input type="image" src="xx.xx">
</form>
I've found that image-buttons DO return a response, but you should NOT use a value-option. What I see returned are two version of the name="MYNAME"
with .X
and .Y
endings.
For example:
<input type="image" src="/path-to/stop.png" name="STOP" width="25" height="25" align="top" alt="Stop sign">
This is within your <form>
to </form>
. If you click the image, what's returned are STOP.X
and STOP.Y
with numeric values. The existence of either indicates the STOP image-button was clicked. You don't need any special code. Just treat it as another kind of "submit" button that returns a pair of augmented NAMEs.
I've tried this on Safari, Firefox and Chrome. The image wasn't displayed with Safari, but where it was supposed to be located, my cursor turned into a finger-icon, and I could click it.
Using the type="image"
is problematic because the ability to pass a value is disabled. Although it's not as customizable and thus as pretty, you can still use your images ao long as they are part of a type="button"
.
<button type="submit" name="someName" value="someValue"><img src="someImage.png" alt="SomeAlternateText"></button>
An input type="image"
only defines that image as the submit button and not as an input that can carry over a value to the server.