Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

JSP Form - Multiple Submit Buttons

  • 28-01-2014 11:43AM
    #1
    Registered Users, Registered Users 2 Posts: 8,324 ✭✭✭


    I'm using an to display a list of objects. This is my code for displaying them. I have two different version for different objects.

    Members
    <sf:form id="details" method="post"
            action="${pageContext.request.contextPath}/approveFinalize"
            commandName="toApprove">
            <table class="members">
                <tr>
                    <td>Name</td>
                    <td>Grade</td>
                    <td>Email</td>
                    <td>Member Type</td>
                    <td>Contact Number</td>
                </tr>
                <c:forEach var="row" items="${toApprove}">
                    <tr>
                        <td>${row.name}</td>
                        <td>${row.grade}</td>
                        <td><input type="hidden" value="${row.username}" name="username"/><a href="mailto:${row.username}">Email</a></td>
                        <td>${row.member_type}</td>
                        <td>${row.contact_num}</td>
                        <td><input value="Approve" type="submit" />
                    </tr>
                </c:forEach>
            </table>
        </sf:form>
    

    With that fellow, once I user is approved, it changes the status from 0 to 1 (which works fine), and then reloads query to remove. No matter what I do, if I have 5 unapproved, the button always approves the first result, even though I may have hit the 4th submit button.

    I also have a Tournament version

    Tournament
    <sf:form id="details" method="post"
            action="${pageContext.request.contextPath}/tournamentRegister"
            commandName="tournament">
            <table class="members">
                <tr>
                    <td>ID</td>
                    <td>Name</td>
                    <td>Type</td>
                    <td>Singles/Doubles</td>
                    <td>Level (Senior/Junior)</td>
                    <td>Style</td>
                </tr>
                <c:forEach var="row" items="${tournaments}">
                    <tr>
                        <td><input type="hidden" value="${row.id}" name="tournamentID" />${row.id}</td>
                        <td>${row.tournamentName}</td>
                        <td>${row.tournamentGender}</td>
                        <td>${row.tournamentType}</td>
                        <td>${row.tournamentCategory}</td>
                        <td>${row.tournamentStyle}</td>
                        <td><input value="Register" type="submit" /></td>
                    </tr>
                </c:forEach>
            </table>
        </sf:form>
    
    This issue here is that when it displays the tournaments, which don't disappear currently once you register, it always returns the id of the first entry. It's more than likely the same solution, and I'm messing up with how I'm implementing the form submission.


Comments

  • Technology & Internet Moderators Posts: 28,863 Mod ✭✭✭✭oscarBravo


    I'd put the <form> tags inside the forEach loop to create separate forms, each with its own input and submit button.


  • Registered Users, Registered Users 2 Posts: 12,027 ✭✭✭✭Giblet


    You could do the above or you could also use the formaction property of button which works on newer browsers, but might require you passing the id in the url, probably not idea. I would probably do this with a hidden checkbox that gets selected via javascript, before the form is submitted. You can then read the selected values and take action on them.


  • Registered Users, Registered Users 2 Posts: 8,324 ✭✭✭chrislad


    Cheers. I actually sorted it with the first answer. I don't really want to use javascript as it can be disabled, and may not work on mobile browsers.

    Thanks for the replies!


Advertisement