Reputation: 23
I have a HTML form and want to process it through my Controller. But if I want to access a field and for example Log it or print it out, it always gives me a null value
Does someone know why?
Controller:
public static Result register() {
DynamicForm users = Form.form().bindFromRequest();
Logger.info(users.get("vorname"));
return ok("hallo " + users.get("vorname"));
}
View:
<form role="form" class="form-horizontal" action="@routes.Signup.register()" method="POST">
<div class="form-group">
<label for="vorname" class="col-sm-2 control-label">Vorname</label>
<div class="col-sm-10">
<div class="col-xs-4">
<input type="text" class="form-control" id="vorname" placeholder="Vorname">
</div>
</div>
</div>
<div class="form-group">
<label for="nachname" class="col-sm-2 control-label">Nachname</label>
<div class="col-sm-10">
<div class="col-xs-4">
<input type="text" class="form-control" id="nachname" placeholder="Nachname">
</div>
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email-Adresse</label>
<div class="col-sm-10">
<div class="col-xs-4">
<input type="email" class="form-control" id="email" placeholder="Email-Adresse">
</div>
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label">Passwort</label>
<div class="col-sm-10">
<div class="col-xs-4">
<input type="password" class="form-control" id="password" placeholder="Passwort">
</div>
</div>
</div>
<div class="form-group">
<label for="rpassword" class="col-sm-2 control-label">Passwort wiederholen</label>
<div class="col-sm-10">
<div class="col-xs-4">
<input type="password" class="form-control" id="rpassword" placeholder="Passwort wiederholen">
</div>
</div>
</div>
<div class="form-group">
<label for="geschlecht" class="col-sm-2 control-label">Geschlecht</label>
<div class="col-sm-10">
<div class="col-xs-4">
<select class="form-control" id="geschlecht">
<option>Männlich</option>
<option>Weiblich</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="col-xs-4">
<button type="submit" class="btn btn-default">Registrieren</button>
</div>
</div>
</div>
</form>
Upvotes: 2
Views: 1271
Reputation: 426
I think you should use:
DynamicForm form = new DynamicForm().bindFromRequest();
I also encourage you to use form helpers just to make sure that everything is configured properly. https://playframework.com/documentation/2.3.x/JavaFormHelpers
Edit. Yes, you should use definitely use helpers. You forgot to put "name" attribute in your vorname input. This attribute, not id is essential in handling forms.
Upvotes: 1