Reputation: 122
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
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