Results 1 to 10 of 10

Thread: Forms with multiple submits

Hybrid View

  1. #1

    Default 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?
    cheers,
    Lili

  2. #2
    Join Date
    Aug 2004
    Location
    Denver
    Posts
    249

    Default

    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

  3. #3

    Default

    That makes sense.
    Thanks.
    cheers,
    Lili

  4. #4
    Join Date
    Apr 2005
    Posts
    9

    Default

    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

  5. #5
    Join Date
    Aug 2004
    Location
    Denver
    Posts
    249

    Default

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

  6. #6
    Join Date
    Apr 2005
    Posts
    9

    Default

    sorry mraible

    can u please make that little more elaborate ..

    thanx

  7. #7
    Join Date
    Aug 2004
    Location
    Denver
    Posts
    249

    Default

    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. ;-)

  8. #8
    Join Date
    Aug 2004
    Posts
    29

    Default

    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.

  9. #9
    Join Date
    Apr 2005
    Posts
    9

    Default

    thank u mraible
    it worked

    also rharing for ur suggestion ..

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

    thanx

  10. #10
    Join Date
    Oct 2004
    Location
    London, UK
    Posts
    71

    Default

    have a look at

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

    for a more generic form handler with multiple submits
    Stuart Eccles
    Technical Consultant

Similar Threads

  1. Replies: 2
    Last Post: Oct 6th, 2005, 12:31 PM
  2. Replies: 1
    Last Post: Mar 9th, 2005, 03:52 PM
  3. Replies: 1
    Last Post: Feb 25th, 2005, 07:12 AM
  4. Replies: 4
    Last Post: Jan 21st, 2005, 08:43 AM
  5. Replies: 1
    Last Post: Jan 6th, 2005, 11:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •