Reputation: 13
Hallo guys im new to the playframework and run into a little problem regarding form handling. Here is my view
<form action="@routes.Account.changeemail()" method="Post">
email:<input name ="email">
<button type="submit" name="action" value="Change_email">save</button>
<br />
</form>
<form action="@routes.Account.changepassword()" method="Post">
password:<input name ="password">
<button type="submit" name="action" value="change_password">save</button>
</form>
<br />
And here is my controller
public static Result changeemail(){
final DynamicForm form = Form.form().bindFromRequest();
Logger.info(form.get("email"));
return TODO;}
public static Result changepassword(){
final DynamicForm forms = Form.form().bindFromRequest();
Logger.info(forms.get("password"));
return TODO;}
Here the routes:
GET /account controllers.Account.accountview()
POST /account controllers.Account.changeemail()
POST /account controllers.Account.changepassword()
The problem is if i press the Change_email button it does the right thing, but if i press the password button it is doing the changeemail action , even if it should handle the changepasswort action. I checked it with the firefox networkanalysis and it seems that it is sending the correct action.
In forward thanks for the help
Greetings Alex
Upvotes: 0
Views: 662
Reputation: 4426
The problem comes from your routes, the order is important. Your router always takes the first POST /account
which executes the changeemail()
action. You can't have POST /account
for two different actions. It should be :
GET /account controllers.Account.accountview()
POST /account/change-email controllers.Account.changeemail()
POST /account/change-password controllers.Account.changepassword()
Upvotes: 2