Page 1 of 1

Multiple submit buttons, images, and variables

Posted: Sat Aug 24, 2002 8:50 am
by Bill H
My form has one selection box, and after making the selection the user clicks "Revise," "Delete" or "Print" button.

To use multiple submit buttons in a form and have each button pass a variable to identify which one was clicked:

Code: Select all

print("<input  type=submit name=Submit Value=Revise>");
print("<input  type=submit name=Submit Value=Delete>");
print("<input  type=submit name=Submit Value=Print>");
That passes the variable $Submit with content "Revise," "Delete" or "Print." But I want to use images for the buttons:

Code: Select all

print("<input type=image name=Submit value=Revise src="Add.gif">");
etc.
Doesn't pass the $Submit variable at all.

So how can I use multiple submit button images and inform the receiving php file which one was clicked along with the selection that was made?.

Posted: Sat Aug 24, 2002 9:06 am
by protokol
You must give each button a different name attribute

Posted: Sat Aug 24, 2002 9:14 am
by volka
for <input type="image".... you get the coordinates of where the user clicked within that image.
if you use something like

Code: Select all

<form method="POST">
	<button type="submit" name="submit">
		<img src="netsc3.gif" value="test" />
	</button>
</form>
you'll receive $_POST['submit'] == "<IMG src=\"netsc3.gif\" value=\"test\">"
not as comfortable as <input type="submit"/> but at least you may search the value with preg_match or similar.

:!: There maybe another simpler solution

Posted: Sat Aug 24, 2002 9:23 am
by Bill H
volka, thanks! Actually I think I knew that at one time, but had completely forgotten it.

Which leads me to a simpler solution: one image which includes all three buttons.
The location will tell me which button within that single image was clicked.

It will take me some dithering, but it should be quite elegant.

Thanks again.

PS: anyone notice that from original question to solution answer was less that half an hour? Wow, I didn't expect that! Super.