In Play 2.0 Scala application I have simple page with Form with one parameter. It redirects to another page, where I want to do something with parameter from the form. How can I get it?
I'm looking for something like
request.formData.get("paramName")
I know request.body, but still don't know how to get single parameter value from it.
I'd say that the easyest way to retrieve forms data is to use the Form structure in play.api.data. So here is how you could do it in play2.0-rc1
val form = Form[(String, String)](
tuple(
"paramName1" -> nonEmptyText,
"paramName2" -> nonEmptyText
)
)
form.bindFromRequest.fold(
failure => (),//do smthg with the failure info
{ case (p1, p2) => println(p1);println(p1)}
)
Instead of using nonEmptyText you might use of[String].
Check what is put in your hands for that mapping here Forms Helper. Some other information that should help you further are here.
If a post request with following may work
request().body().asFormUrlEncoded().get("myparam")[0];
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