You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jon Wilmoth <jw...@esagegroup.com> on 2001/03/23 18:37:59 UTC

Multiple Submits per Form

After sifting through the archives, I only found one previous question about handling multiple submit buttons in the same form.  The solution that was proposed, was to read the label of the submit button present on the http request params to figure out which button was actually submitted.  However, this will not work (gracefully*) with internationalization.  If the client facing label, the "value" attribute of the submit jsp tag, is used to determine the code would need to check for "Login", "Inloggen" (Dutch), "sich anmelden" (German), etc.  If I may suggest a hidden field that is submitted (value set at button click by javascript) that is generated by the form tag, with a constant for the name.  This decouples the presentation from the application flow.  Thoughts?

*The most "graceful" solution I could think of would be to do a reverse lookup in the message catalog for the local specific value.


************************************************
Jon Wilmoth
Software Architect
eSage Group
(206) 264-5675  (Voice & Fax)
jwilmoth@esagegroup.com
http://www.esagegroup.com

Re: Multiple Submits per Form

Posted by Peter Alfors <pe...@irista.com>.
Jon,

Here is one solution, which Im sure there are many:

Each method that you you want to perform will point to a different
action.
Each method will be executed using an INPUT - button.
The buttons will execute a javascript call that will set the form action
and submit the form.

So your page would look something like this:

<HTML>
    <HEAD>
        <SCRIPT language="JavaScript">
            function performAction(theAction)
            {
              document.myForm.action = theAction;
              document.myForm.submit(document.myForm);
            }
        </SCRIPT>
    </HEAD>
<BODY>
    <FORM name="myForm" id="myForm" method="post">
           ... <your page stuff> ...
        <INPUT type="button" name="btnAction1" id="btnAction1"
value="LocalizedAction1Text" onClick="performAction('ActionOne.do')">
        <INPUT type="button" name="btnAction2" id="btnAction2"
value="LocalizedAction2Text" onClick="performAction('ActionTwo.do')">
    </FORM>
</BODY>
</HTML>

This way, the name of the button can be localized, and not affect the
action.

HTH,
    Pete

Jon Wilmoth wrote:

> After sifting through the archives, I only found one previous question
> about handling multiple submit buttons in the same form.  The solution
> that was proposed, was to read the label of the submit button present
> on the http request params to figure out which button was actually
> submitted.  However, this will not work (gracefully*) with
> internationalization.  If the client facing label, the "value"
> attribute of the submit jsp tag, is used to determine the code would
> need to check for "Login", "Inloggen" (Dutch), "sich anmelden"
> (German), etc.  If I may suggest a hidden field that is submitted
> (value set at button click by javascript) that is generated by the
> form tag, with a constant for the name.  This decouples the
> presentation from the application flow.  Thoughts? *The most
> "graceful" solution I could think of would be to do a reverse lookup
> in the message catalog for the local specific
> value.  ************************************************
> Jon Wilmoth
> Software Architect
> eSage Group
> (206) 264-5675  (Voice & Fax)
> jwilmoth@esagegroup.com
> http://www.esagegroup.com