I found this neat post before asking this question (but doesn't solve my problem) :
I'm trying to update a record with ajax call using play framework as a backend.
Here is some data regarding my request :
Request URL:http://172.20.12.50:9000/updateName
Request Method:PUT
Form Data
name=&value=Testttt&pk=367
Here is how I try to test what I get on the server side :
Logger.info("PK IS " + request().getQueryString("pk"));
This is what I get in the log:
[info] application - PK IS null
How would I get these params from FormData? I got this data regarding my request from firebug
Adapted from http://www.playframework.com/documentation/2.0/ScalaForms
import play.api.data._
import play.api.data.Forms._
case class MyFormData(name: Option[String], value: String, pk: Long)
val myForm = Form(
mapping(
"name" -> optional(text),
"value" -> text,
"pk" -> number
)(MyFormData.apply)(MyFormData.unapply)
)
myForm.bindFromRequest.fold(
formWithErrors => // binding failure, you retrieve the form containing errors,
value => // binding success, you get the MyFormData value
)
Obviously substitute MyFormData
for something meaningful to your domain.
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