Re: 2 submit buttons.
| From: | tolga | Date: | Tue, 15 Feb 2011 01:11:32 +0000 |
| Subject: | Re: 2 submit buttons. | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-311291@lists.php.net to get a copy of this message | ||
15.02.2011 00:24, Paul M Foster yazmış:
On Mon, Feb 14, 2011 at 05:15:11PM -0500, Floyd Resler wrote:JS: function send ( selectedtype ) { document.formname.postingvalue.value = selectedtype ; document.formname.submit() ; } html: <form name=formname> <input type="hidden" name="postingvalue" /> <a href="javascript:send('1')">Button 1</a></td> <a href="javascript:send('2')">Button 2</a></td> <a href="javascript:send('3')">Button 3</a></td> php: if($_POST['postingvalue']=="1") { code here } elseif ($_POST['postingvalue']=="1") { code 2 here } bla blaOn Feb 14, 2011, at 4:18 PM, Paul M Foster wrote:Yeah, but you don't even have to go that far. Just put a print_r($_POST) at the beginning of the file, and you'll see which button gets pressed. It will show up in the POST array. Paul this could also work;On Mon, Feb 14, 2011 at 03:35:02PM -0400, Paul Halliday wrote:If you don't mind using a little JavaScript you can test for which button should fire when enter is pressed. How I would do it is to first add a hidden field and call it "buttonClicked". Now, in the text field where you would like a button to fire if enter is pressed, at this to the tag: onkeyup="checkKey(this,event)". For the JavaScript portion of it, do this:I have 2 buttons on a page: if (isset($_POST['botton1'])) {dothing1();} if (isset($_POST['button2'])) {dothing2();} They both work as intended when I click on them. If however I click within a text box and hit enter, they both fire. Is there a way to stop this?Check your code. My experience has been that forms with multiple submits will fire the *first* submit in the form when you hit Enter in a text field or whatever. I just tested this and found it to be true. Now, I'm doing this in Firefox on Linux. I suppose there could be differences among browsers, but I suspect that the specs for HTML mandate the behavior I describe. Paul