Reputation: 37934
this is my code where i need to retrieve data sent in POST:
@play.db.jpa.Transactional
public static Result registered(String fullname, String email, String password, String username) {
if(fullname.isEmpty()){
return badRequest("<p>fehlerhafte eingabe!</p>").as("text/html");
} else {
User user = new User();
user.fullname = fullname;
user.email = email;
user.password = password;
user.username = username;
user.save();
}
String success = "Successful registered!";
return ok(register.render(success));
}
and this is my user class:
public class User extends Model {
private static final long serialVersionUID = 1L;
public String fullname;
@Email
public String email;
@Required(message="Username erforderlich!")
public String username;
@Transient @Required
public String password;
public User(){}
public User(String username, String password, String fullname, String email) {
this.username = username;
this.password = password;
this.email = email;
this.fullname = fullname;
}
and this is my html:
<form method="post" action="@routes.Application.registered()">
<p id="login_panel">@success</p>
fullname: <input type="text" name="fullname" id="fullname" value=""/>
email: <input type="text" name="email" id="email" value=""/>
username: <input type="text" name="username" id="username" value=""/>
password: <input type="password" name="password" id="password" value=""/>
<button type="submit">Register</button>
</form>
and this is in my routes:
POST /registered controllers.Application.registered()
What is WSRequest? can this be the clue for my problem?
i appreciate any help! thanks thanks
Upvotes: 2
Views: 2507
Reputation: 4690
You need to check the controller class code. You should have all field names as parameter in the called controller method. Then you can use these filed in your application.
Upvotes: 0
Reputation: 21564
You "registered" action does not need any parameter.
These parameters are provided within the request, and you'll get them by using the built in form binding:
public static Result registered(String fullname, String email, String password, String username) {
User user = form(User.class).bindFromRequest().get();
....
}
Upvotes: 2