Re: [PHP] Using custom button form element instead of standard submit?
Durwood Gafford [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... To make the issues more clear (assuming everyone's not totally burned out thinking about this one), I will submit links to working, example code in a followup post. I'm swamped with a proposal i'm working on for my 'day' job, however -- so stay tuned. you can go to http://www.berzerker.net/durwood/phptest and see 3 samples of a simple directory traversal php script ... this is, in essence, the problem i'm facing. Read the readme.txt file there for more info .. but basically there are 2 solutions that work but aren't optimal ... and one that don't work. and i couldn't figure out how to do the image version -- it's explained in teh readme file. so if anyone can come up with a better solution, let me know! thx, durwood -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using custom button form element instead of standard submit?
sure this would work but it'd be VERY inefficient in my application. It's a file browser application so i have hundreds of folder icons on a page .. the 'submit' element will pass back the name of the button clicked and it would be available immediately/directly, which is what i want. BUT an 'image' element would require me to loop through ALL buttons doing an 'isset' test on each one. I can't believe html provides no means for using an icon as a submit button. well i'm off pursuing a javascript solution now. by the way .. unrelated question ... why would one want to use $_REQUEST['foo'] instead of just $foo? doesn't php give you access to form variables using the latter construct which is much cleaner? Philip Olson [EMAIL PROTECTED] wrote in message Pine.BSF.4.10.10301300503280.83137-10@localhost">news:Pine.BSF.4.10.10301300503280.83137-10@localhost... [snip] I assume i could use solution A above, and parse the _x out of the name value .. but this seems pretty hoaky and it's my understanding soultion B is [snip] This is how it's done. If this is set, the button was clicked. For example: if (isset($_REQUEST['thebuttonname_x'])) { print The button was clicked; } Regards, Philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using custom button form element instead of standard submit?
At 12:18 30.01.2003, Durwood Gafford spoke out and said: [snip] sure this would work but it'd be VERY inefficient in my application. It's a file browser application so i have hundreds of folder icons on a page .. the 'submit' element will pass back the name of the button clicked and it would be available immediately/directly, which is what i want. BUT an 'image' element would require me to loop through ALL buttons doing an 'isset' test on each one. [snip] ??? input type=submit name=sample_a input type=image name=sample_b src=myimg.gif With the first method, you'd need to test for a button named 'sample_a'. For the second method, you'd need to test for a button named 'sample_b_x'. So where's the difference? You need to loop through all available button names anyway, orhave I completely misunderstood your question? -- O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using custom button form element instead of standard submit?
To add to my message, you could: $buttons = array('sample_a_x', 'sample_b', 'sample_c_x'); $button_pressed = array_intersect($buttons, array_keys($_REQUEST)); If you have everything perfect, i.e. all available buttons are held in the array, and there are no other input fields in your form that might name-collide (which wouldn't be good anyway ;-), this will give you an array with exactly one entry if any of the buttons are clicked, be it an image (sample_a, sample_c) or a regular (sample_b) button. -- O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using custom button form element instead of standard submit?
input type=submit name=sample_a input type=image name=sample_b src=myimg.gif With the first method, you'd need to test for a button named 'sample_a'. For the second method, you'd need to test for a button named 'sample_b_x'. no ... with the first example you can have numerous buttons on the same HTML page with the same name and use the 'value' attribute to see which one is pressed. I did this and it works quite elegantly for my application. input type=submit name=sample value=a input type=submit name=sample value=b input type=submit name=sample value=c input type=submit name=sample value=d your php form handler can now simply do: print The user selected button $samplebr\n) otherwise, with the image solution you'd have to do something like this... foreach ($_GET as $button) { if (isset($button)) { $button_name = substr($button, -2, 0); // or whatever to remove the _x print The user selected button substr($button_name); break; } } Although arrays might provide a solution that wouldn't quite be as good as the 'submit' button solution, but not as worse as a straight name-based 'image' solution. Given that the 'button' element with type = submit does NOT work, maybe the javascript solution is the most elegant. but i haven't gotten that to work yet either! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using custom button form element instead of standard submit?
At 13:37 30.01.2003, Durwood Gafford spoke out and said: [snip] input type=submit name=sample value=a input type=submit name=sample value=b input type=submit name=sample value=c input type=submit name=sample value=d your php form handler can now simply do: print The user selected button $samplebr\n) This would display the value as button text. It works, BUT: - you cannot divert content from data or functionality - you have to modify code if you want to modify your page Something that might not be worthwile, depends on the project size. However, if you need to act on a button, you _need_ to test for something, be it the name or the value. Although arrays might provide a solution that wouldn't quite be as good as the 'submit' button solution, but not as worse as a straight name-based 'image' solution. I still don't get it - maybe you could show us your approach to the solution so we can grasp the problem? Given that the 'button' element with type = submit does NOT work, maybe the javascript solution is the most elegant. but i haven't gotten that to work yet either! Now that's more easy: form name=myform input type=hidden name=button value= ... something here input type=image src=img_1.gif onClick=document.forms['myform']['button'].value='button_a'br input type=image src=img_2.gif onClick=document.forms['myform']['button'].value='button_b'br input type=image src=img_3.gif onClick=document.forms['myform']['button'].value='button_c' /form This will give you a $_REQUEST['button'] containing the button value. Note though that this doesn't work if JS has been disabled in the browser, or if the browser doesn't support JS at all. -- O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using custom button form element instead of standard submit?
At 13:37 30.01.2003, Durwood Gafford spoke out and said: [snip] input type=submit name=sample value=a input type=submit name=sample value=b input type=submit name=sample value=c input type=submit name=sample value=d your php form handler can now simply do: print The user selected button $samplebr\n) If that's what you want, then just make each button a normal a href link and pass an variable to the next page in the link (like someone has already suggested). You'd get the same end result. a href=page.php?sample=aimg/a a href=page.php?sample=bimg/a a href=page.php?sample=cimg/a a href=page.php?sample=dimg/a print The user selected button $samplebr\n; ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using custom button form element instead of standard submit?
1lt John W. Holmes [EMAIL PROTECTED] wrote in message If that's what you want, then just make each button a normal a href link and pass an variable to the next page in the link (like someone has already suggested). You'd get the same end result. a href=page.php?sample=aimg/a a href=page.php?sample=bimg/a a href=page.php?sample=cimg/a a href=page.php?sample=dimg/a print The user selected button $samplebr\n; Indeed this solution does appear to be the best in that it does not rely on client-side scripting, it allows for control of the icon/button appearance, and it allows direct access to the value associated with the selected button. I had hoped to use POST instead of GET, however -- i didn't want to pass the information via the URL. To make the issues more clear (assuming everyone's not totally burned out thinking about this one), I will submit links to working, example code in a followup post. I'm swamped with a proposal i'm working on for my 'day' job, however -- so stay tuned. thanks for all of the insights/assistance! -Durwood -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Using custom button form element instead of standard submit?
I can't figure out how to tell which button was pressed by a user when i'm using a button instead of a standard submit form element. This works: input type=submit name=parent value=foo $parent will equal foo This doesn't work: button type=submit name=parent value=fooimg src=icon.gif/button $parent will equal img src=icon.gif NOT foo How do I get the value of foo to be returned in $parent and still use a graphical icon instead of a standard submit button? thanks, durwood ([EMAIL PROTECTED]) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Using custom button form element instead of standard submit?
On 27-Jan-2003 Durwood Gafford wrote: I can't figure out how to tell which button was pressed by a user when i'm using a button instead of a standard submit form element. This works: input type=submit name=parent value=foo $parent will equal foo This doesn't work: button type=submit name=parent value=fooimg src=icon.gif/button $parent will equal img src=icon.gif NOT foo How do I get the value of foo to be returned in $parent and still use a graphical icon instead of a standard submit button? input TYPE=IMAGE NAME=parent VALUE=foo SRC=icon.gif Regards, -- Don Read [EMAIL PROTECTED] -- Beer is proof that God loves us and wants us to be happy. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using custom button form element instead of standard submit?
This suggested solution is not quite what i was looking for (I was aware of it already): A: input TYPE=IMAGE NAME=parent VALUE=foo SRC=icon.gif The above uses an image as a bitmap and gets the x,y values where it was clicked. I'd like to use an ICON (instead of a standard submit button) and only care about WHICH icon was clicked, not where on the bitmap. Presumably the correct HTML is to use the BUTTON type as follows: B: button type=submit name=parent value=fooimg src=icon.gif/button but this does not work. And of course, C: input type=submit name=parent value=foo gives the standard submit button. One suggestion was to add a src=icon.gif attribute to the submit type directly above (example C), but that didn't change the button ... it still had the standard button. I assume i could use solution A above, and parse the _x out of the name value .. but this seems pretty hoaky and it's my understanding soultion B is correct HTML and SHOULD work! Is it a bug in php that it is causing it not to work? or is the button construct depricated? or am i misunderstanding how that BUTTON construct is supposed to work? Sorry to be dense about this but it seems like a simple concept that's frustratingly difficult. -Durwood Don Read [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... On 27-Jan-2003 Durwood Gafford wrote: I can't figure out how to tell which button was pressed by a user when i'm using a button instead of a standard submit form element. This works: input type=submit name=parent value=foo $parent will equal foo This doesn't work: button type=submit name=parent value=fooimg src=icon.gif/button $parent will equal img src=icon.gif NOT foo How do I get the value of foo to be returned in $parent and still use a graphical icon instead of a standard submit button? input TYPE=IMAGE NAME=parent VALUE=foo SRC=icon.gif Regards, -- Don Read [EMAIL PROTECTED] -- Beer is proof that God loves us and wants us to be happy. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php