This is terrific! Thank you Jesse! I just used this solution and added the ability to get a value too. What you can do is add the value to the end of the name attribute seperated by a dash. For example if your name is "imagePressed" the new name would be "imagePressed-3". Then call the below function to extract it out.
function getImageButtonValue($formvars, $name) { // loop through the keys foreach ($formvars as $key => $value) { // if key is what you are looking for if (strstr($key, $name)) { // extract out the value from the name $temp = split('-', $key); // get rid of the _x or _y too $temp = split('_', $temp[(sizeof($temp)-1)]); return $temp[0]; } } // didn't find anything so return false. return false; }
Just becareful if your name attribute or value has dashes or underscores.
I didn't get Pauls solution to work with multiple buttons, but here is my solution without javascript (uses php instead):
and to see which button the user clicked:
if (isset($_POST['img1_x'])) {
unset($_POST['img1_x'],$_POST['img2_y']);
/* do whatever you wan't */
}
else if (isset($_POST['img2_x'])) {
unset($_POST['img2_x'],$_POST['img2_y']);
/* again do whatever you wan't */
}
I have to unset the post values because the user can click first img1 then img2 then again img1 and i just simply sen the whole $_POST array so eventually it would contain both. And still don't get different values, but can play with the different names.
If anyone can make a simpler solution with php i'd be happy to here about it
Comment
This is terrific! Thank you Jesse! I just used this solution and added the ability to get a value too. What you can do is add the value to the end of the name attribute seperated by a dash. For example if your name is "imagePressed" the new name would be "imagePressed-3". Then call the below function to extract it out.
<input type='image' name='imagePressed-3' src='/btn.gif'>
function getImageButtonValue($formvars, $name) {
// loop through the keys
foreach ($formvars as $key => $value) {
// if key is what you are looking for
if (strstr($key, $name)) {
// extract out the value from the name
$temp = split('-', $key);
// get rid of the _x or _y too
$temp = split('_', $temp[(sizeof($temp)-1)]);
return $temp[0];
}
}
// didn't find anything so return false.
return false;
}
Just becareful if your name attribute or value has dashes or underscores.
Hope this helps!
Parent comment
I didn't get Pauls solution to work with multiple buttons, but here is my solution without javascript (uses php instead): and to see which button the user clicked: if (isset($_POST['img1_x'])) { unset($_POST['img1_x'],$_POST['img2_y']); /* do whatever you wan't */ } else if (isset($_POST['img2_x'])) { unset($_POST['img2_x'],$_POST['img2_y']); /* again do whatever you wan't */ } I have to unset the post values because the user can click first img1 then img2 then again img1 and i just simply sen the whole $_POST array so eventually it would contain both. And still don't get different values, but can play with the different names. If anyone can make a simpler solution with php i'd be happy to here about it