Reputation: 3819
am using a form with just one input text and one submit button. I want to forward the text from the input text field to a controller at the backend. perhaps if you take a look at the code snippet it gives a better picture of what I am trying to do.
this is from the index.html page
@helper.form(action=routes.Application.index()){
<input type='text' name='myname' />
<input type='submit' name='mysubmit' value='Create Class' />
}
below is a code snippet from the controller
public class Application extends Controller {
public static Result index() {
return ok(index.render(null)); }
}
the code displays the form as expected but I want to pass the string entered into the input text field to the controller method and then print the text. Like what is presented below.
System.out.println(variable);
where variable is the the test entered into the text field. Any suggestions will be welcomed.
Upvotes: 4
Views: 8375
Reputation: 55798
Use DynamicForm
for that:
public static Result index() {
DynamicForm bindedForm = form().bindFromRequest();
System.out.println(bindedForm.get("myname"));
// or...
Logger.info(bindedForm.get("myname"));
// Play's Logger is nicer than System.out.println();
return ok(index.render(null)); }
}
Upvotes: 12