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.
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)); }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With