note: I'm new to Play Framework
Using this video tutorial and playlist , I was able to create a simple webapp.
Problem:
POST methods in the routes file do not seem to execute the required POST code.
Given the routes file below, looking at localhost:{port}/user/register requires a GET , thus rendering and returning a register view .
Filling out the register view fields and clicking submit , refresh the page (clearing the input fields) and showing the expected "registered" text
If method="post" added to the form in the register view , an immediate 403 Forbidden page appears.
Why isnโt the โregisteredโ text displayed, what am I missing (something is wrong)?
Route File:
GET / controllers.HomeController.index GET /user controllers.LoginController.index() GET /user/login controllers.LoginController.login() POST /user/login controllers.LoginController.doLogin() GET /user/register controllers.LoginController.register() POST /user/register controllers.LoginController.doRegister() # Map static resources from the /public folder to the /assets URL path GET /assets
Controllers
HomeController LoginController
LoginController methods:
public Result index() { return ok(views.html.user.index.render(User.getAllUsers())) } public Result login() { return ok(login.render()); } public Result doLogin() { return ok("registered"); } public Result register() { return ok(register.render()); } public Result doRegister() { return ok("registered"); }
Registration:
@() <html> <head> <title>Register new User</title> </head> <body> <h1>Register User</h1> <br> <br> Enter Email Address: <input type="password" name="confirmPassword"> Enter Password: <input type="password" name="confirmPassword"> Confirm Password: <input type="password" name="confirmPassword"> <br> <br> <form action="@routes.LoginController.doRegister()"> <input type="submit" value="Register"/> </form> </body> </html>
Console output error:
[warn] p.filters.CSRF - [CSRF] Check failed because no or invalid token found in body [warn] p.filters.CSRF - [CSRF] Check failed with NoTokenInBody