Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

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,830 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: 11,989 ✭✭✭✭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