Multiple submit buttons, images, and variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Multiple submit buttons, images, and variables

Post 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?.
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

You must give each button a different name attribute
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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.
Post Reply