James2707
James2707

Reputation: 122

Play Framework 2.3.2 with 2 submit buttons

I have a form with two submit buttons, one to save and other to save and create new one. I need to know in the controller which button the user pressed in the form. I tried several solutions I found on the internet but none helped me. I do not know if it's the version of play framework. I'm using play framework 2.3.2 with Java Thanks!

Upvotes: 0

Views: 1007

Answers (1)

Dieter Rehbein
Dieter Rehbein

Reputation: 991

I've done it this way (maybe there is a better solution but it works):

The view:

@helper.form(action=routes.MyController.myMethod() {

.....

<input type="submit" value="update"     name="update" >
<input type="submit" value="create new" name="createNew" >
}

An the Controller:

public static Result myMethod() throws IOException {
    ....
    DynamicForm requestData = Form.form().bindFromRequest();

    if (requestData.get("update")!=null) {
        // do the update
    } else if (requestData.get("createNew")!=null) {
        // create a new one
    }
}

Upvotes: 2

Related Questions