Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play 2.0 framework - POST parameters

I'm trying to POST parameters to Action, and wrote in the routes:

# Home page
GET    /                         controllers.Application.index()

POST   /login/name:/password:    controllers.Application.login(name, password)

and I have an Action

public static Result login(String name, String password) {
    return ok(name + " "  + password);
}

my form is

<form action="/login" method="post">

    <input name="name" type="text" id="name">
    <input name="password" type="password" id="password">
    <input type="submit" value="Login">

</form>

And it doesn't work

For request 'POST /login' [Missing parameter: name]

What am i doing wrong?

like image 746
HackU Avatar asked Jun 13 '12 03:06

HackU


2 Answers

Simply change the route to the following:

POST   /login    controllers.Application.login(name, password)

By NOT including the dynamic names (:name and :password) in the routing path, the assumption is that the variables come from the request (IE: your html inputs)

The error you are getting indicates that name and password do not appear in the url path... which is correct because the path you specified in your routes indicates the path should look something like this:

/login/myname/mypassword

Please check http://www.playframework.org/documentation/2.0.1/JavaRouting and look at the section called "Call to action generator method"

like image 86
Howard Avatar answered Oct 26 '22 10:10

Howard


your route should not include dynamic parts (name, password) since the data is in the body and not the url

like image 37
asawilliams Avatar answered Oct 26 '22 09:10

asawilliams