Announcement Announcement Module
Collapse
No announcement yet.
Forms with multiple submits Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Forms with multiple submits

    I have a form that is for editing a object (Like EditStudentForm) and it extends SimpleFormController. I have 2 submit buttons on the form "Save" and "Delete". How can I execute the appropriate method based on which button has been clicked?

  • #2
    I would just name your buttons "save" and "delete". Then in your onSubmit() method, you can add logic to detect which button was clicked:

    Code:
    if (request.getParameter("save") != null) {
        // do save logic
    } 
    
    if (request.getParameter("delete") != null) {
        // do delete logic
    }
    The button's name is only sent in the request when the user clicks on it.

    Hope this helps,

    Matt

    Comment


    • #3
      That makes sense.
      Thanks.

      Comment


      • #4
        i have the same problem
        but i am using

        <INPUT type="image" src="images/icon_last.gif" name="last" value="Last">

        but this does not work

        if (request.getParameter("last") != null) {
        }

        can't i use input type image for submitting and detect that in controllers

        thanx

        Comment


        • #5
          I believe you have to use "last.x" or "last.y" or something funky like that.

          Comment


          • #6
            sorry mraible

            can u please make that little more elaborate ..

            thanx

            Comment


            • #7
              I haven't tried it myself, but I know image-based submit buttons send "x" and "y" coordinates, rather than their name. Try this:

              Code:
              if &#40;request.getParameter&#40;"last.x"&#41; != null&#41; &#123;
              &#125;
              It's just a hunch, I could be completely wrong. ;-)

              Comment


              • #8
                or use a hidden field (e.g. navigate) and use a javascript method to fill this field e.g. <input type="image" onclick="document.mainForm.navigate.value='submitB yImage'">
                or something similar.

                Comment


                • #9
                  thank u mraible
                  it worked

                  also rharing for ur suggestion ..

                  actually i am trying to avoid javascripts .. so will use mraibles method

                  thanx

                  Comment


                  • #10
                    have a look at

                    http://forum.springframework.org/viewtopic.php?t=1588

                    for a more generic form handler with multiple submits

                    Comment

                    Working...
                    X