Coldfusion - checking if <input type="image" /> was clicked

Im using an image input field and i need to check if it was clicked

For <input type=“submit” /> i can just do

<cfif isDefined("FORM.MySubmitButton")>
 	// Do Stuff

but this doesnt work with <input type=“image” />, it is never defined.

any ideas?

<input type="image" name="MySubmitButton" />

Always name your form elements. Eliminates the guess work.

i always do a switch on cgi.request_method, its the most portable.

<cfswitch expression=“#cgi.request_method#”>
<cfcase value=“GET”>
the form goes here
<cfcase value=“POST”>
form processing here

man, its cfswitch day!

The problem is ive more than one submit button on my form. One button is for saving, one button is for deleting selected items.

 <form action="file.cfm" method="post">
 	// form stuff in here
 	<input type="submit" name="SaveItemsButton" value="Save" />
 	<input type="submit" name="DeleteSelectedItemsButton" value="Delete" />

When the above form is submitted, i can check which button was clicked by going

 <cfif isDefined("Form.SaveItemsButton")>
 	// code to save 
 </cfelseif isDefined("Form.DeleteSelectedItems")>
 	// code to delete

This works fine. But i want to be able to do the same thing with the inputs being of type “image” instead of “submit”. Is this possible?

If you want to see that an image button was clicked, try this:

<input type="image" name="mysubmit" />

<cfif isDefined("Form.mysubmit.x")>
//code for imagebutton clicks

Image buttons send more than one value:

[name].x - x-coordinate of where in the image it was clicked.
[name].y - y-coordinate of where in the image was clicked.
[name] - value of the image button input.

Cheers man

Weird how Form.MySubmit isnt defined but Form.MySubmit.x is


ok, got to use the ‘value’ attribute for the input tag for Form.MySubmit to be defined