get the value from image button

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
valen53
Forum Contributor
Posts: 137
Joined: Tue Aug 27, 2002 9:29 am

get the value from image button

Post by valen53 »

The below 1 is image button. I want to get this button value.
But it not same with button that can get the value.

So any way can get the value from image button ?

<input name="Image1" value="Search" type="image" src="images/ql_ntu1.gif" >
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you want php to get the "value" ? From what I remember, image inputs don't have a value per se, as they submit the x,y coordinates you clicked.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

A button can only have one value, correct? Then you can determine which button was clicked by seeing which values (xy coords) are defined and which ones are not.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

or couldn't you always set an action or onclick action? =P forcing it to run a js function that will report it had been clicked? works for me...

especially with the <button> operator since you can embed images within it and completely control the way it behaves as a button instead of the common <Input type="button"> where you are limited to what you can do...
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Well, since JS is a client side langauge, there's no guarantee it will work. I think my way is the best:

Untested

Code: Select all

$form_buttonpairs['image1'] = "Search";
//Add extra values as needed

foreach($form_buttonpairs as $key => $value) {
  if (isset($_POST[$key])) {
    $_POST[$key] = $value;
  }
}
You're allowed to overload $_POST values right?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

not to try and argue, but there is most definately a way for it to work.. i use it all the time ;)

i'm not gonna write the entire thing, but all it boils down to is doing a simple :
<button onclick=jsscript('myvaluetopass'); name="bob">

jsscript could then say document.location.replace('bob.php?value=$valuepassed')

php just does a $_GET['value'], boom bam splat, ye get what you needed...
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Err... I'm not trying to say your solution 'wouldn't' work under most circumstances. I'm saying that you can't always expect "JavaScript" to be there for you. I'm pretty sure we can handle this entirely on the server side, so there's no need to introduce Client Side Scripting.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

to each his own i guess :lol:
Post Reply