RE: Submitting forms to alternate actions
Michael How do you get the values for SUBMIT_xxx.do out of the request ? I don't see any attribute or parameter in the request with name "name" or "SUBMIT_xxx.do" I think I may have misunderstood - Nes # -Original Message- # From: Michael Westbay [mailto:[EMAIL PROTECTED]] # Sent: Tuesday, December 05, 2000 5:55 AM # To: [EMAIL PROTECTED] # Subject: Re: Submitting forms to alternate actions # # # Richards-san wrote: # # With JavaScript you can specify the form action, so you'd have # something like: # # form name="aForm" action="defaultAction.do" # onSubmit="return checkSubmit(this);" # input type="submit" name="button1" value="use # default action" # input type="submit" name="button2" value="use # other action" onClick="document.aForm.action='otherAction.do';" # /form # # I tried that in a web application a long time ago. Worked great with # Netscape, the action never changed in IE3. I'd gotten so fed up with # IE from that and other projects, that I avoid client-side scripting # as much as possible. # # However, it shouldn't be hard to write an Action that will handle # forwarding the action. Something like: # # form name="aForm" action="dispatcherAction.do" # onSubmit="return checkSubmit(this);" # input type="submit" name="SUBMIT_defaultAction.do" # value="use default action" # input type="submit" name="SUBMIT_otherAction.do" # value="use other action" # /form # # Then, have dispatcherAction look for which SUBMIT_xxx.do was sent, # take the suffix, and forward. There you have a general action # dispatcher for all your forms. Just don't name any fields other # than submit buttons to anything with a "SUBMIT_" prefix. # # The only problem I can see with this is when one can hit enter instead # of a button. Oh, but can't that only happen when there is if # ((one and # only one edit box) and (one and only one submit button))? Maybe it # is OK for all cases. # # -- # Michael Westbay # Work: Beacon-IT http://www.beacon-it.co.jp/ # Home: http://www.seaple.icc.ne.jp/~westbay # Commentary: http://www.japanesebaseball.com/ #
Re: Submitting forms to alternate actions
Andris-san wrote: How do you get the values for SUBMIT_xxx.do out of the request ? I don't see any attribute or parameter in the request with name "name" or "SUBMIT_xxx.do" The "xxx" is the variable part. Take the following page and load it in your browser: --- begin test.html --- html body form name="aForm" action="test.html" input type="submit" name="SUBMIT_defaultAction.do" value="use default action" input type="submit" name="SUBMIT_otherAction.do" value="use other action" /form /body /html --- end test.html --- Now, click on "use default action". What is the resulting URL? I get: file:/home/westbay/test.html?SUBMIT_defaultAction.do=use+default+action By giving a submit button a name, that name and value will be passed with the form. This allows you a variable for what action to take on the server side. I'm more accustomed to servlets than JSP still, so I may be missing something here, but one can Enumerate the passed parameters, correct? Go through the list of passed parameters until you come across: if (key.startsWith("SUBMIT_")) { doAction(key.substring(7)); } The value of the submit button ("use+default+action") can be discarded. This method also works with image submit buttons, except you want to trim off the ".x" and/or ".y" at the end of the key, and ignore one of ".x" or ".y". I hope that this helps to clarify it. -- Michael Westbay Work: Beacon-IT http://www.beacon-it.co.jp/ Home: http://www.seaple.icc.ne.jp/~westbay Commentary: http://www.japanesebaseball.com/
Submitting forms to alternate actions
Hi all: I have used struts to set up a simple application. My problem comes up when I want to submit a form to different actions, depending on which button the user presses. If the contents of the form were not important, I could simply GET a different URL (each mapped to a different action) for each button. However, when I need the contents of the form so that the form must be POSTed, then I am stuck -- as far as I can tell, there is only one url that a form can be posted to. Is there a way to override the form's coded post action based on which button is pressed? - Steve -- Steven Peterson, President Frontier Productions, Inc. 310 Wesley Drive Chapel Hill, NC 27516 http://www.frontierproductions.net Tel: 919-942-1386 Fax: 919-933-2677
Re: Submitting forms to alternate actions
With JavaScript you can specify the form action, so you'd have something like: form name="aForm" action="defaultAction.do" onSubmit="return checkSubmit(this);" input type="submit" name="button1" value="use default action" input type="submit" name="button2" value="use other action" onClick="document.aForm.action='otherAction.do';" /form You can also mess around with the form onSubmit action, but I was having trouble trying to determine which button was clicked through that method. This seemed a lot cleaner. Steven Peterson wrote: Hi all: I have used struts to set up a simple application. My problem comes up when I want to submit a form to different actions, depending on which button the user presses. If the contents of the form were not important, I could simply GET a different URL (each mapped to a different action) for each button. However, when I need the contents of the form so that the form must be POSTed, then I am stuck -- as far as I can tell, there is only one url that a form can be posted to. Is there a way to override the form's coded post action based on which button is pressed? - Steve -- Steven Peterson, President Frontier Productions, Inc. 310 Wesley Drive Chapel Hill, NC 27516 http://www.frontierproductions.net Tel: 919-942-1386 Fax: 919-933-2677
Re: Submitting forms to alternate actions
Richards-san wrote: With JavaScript you can specify the form action, so you'd have something like: form name="aForm" action="defaultAction.do" onSubmit="return checkSubmit(this);" input type="submit" name="button1" value="use default action" input type="submit" name="button2" value="use other action" onClick="document.aForm.action='otherAction.do';" /form I tried that in a web application a long time ago. Worked great with Netscape, the action never changed in IE3. I'd gotten so fed up with IE from that and other projects, that I avoid client-side scripting as much as possible. However, it shouldn't be hard to write an Action that will handle forwarding the action. Something like: form name="aForm" action="dispatcherAction.do" onSubmit="return checkSubmit(this);" input type="submit" name="SUBMIT_defaultAction.do" value="use default action" input type="submit" name="SUBMIT_otherAction.do" value="use other action" /form Then, have dispatcherAction look for which SUBMIT_xxx.do was sent, take the suffix, and forward. There you have a general action dispatcher for all your forms. Just don't name any fields other than submit buttons to anything with a "SUBMIT_" prefix. The only problem I can see with this is when one can hit enter instead of a button. Oh, but can't that only happen when there is if ((one and only one edit box) and (one and only one submit button))? Maybe it is OK for all cases. -- Michael Westbay Work: Beacon-IT http://www.beacon-it.co.jp/ Home: http://www.seaple.icc.ne.jp/~westbay Commentary: http://www.japanesebaseball.com/