Commits

Micha Kops  committed b467b9f

Form examples added.

  • Participants
  • Parent commits adf4926

Comments (0)

Files changed (5)

File app/controllers/Application.scala

 object Application extends Controller {
 
   def index = Action {
-
     Ok(views.html.index("It works!", Seq(Item("tim", LocalTime.now(), "hey there"), Item("ted", LocalTime.now(), "whats up.."))))
   }
 

File app/controllers/Data.scala

+package controllers
+
+import play.api.data._
+import play.api.data.Forms._
+import play.api.mvc.Action
+import play.api.mvc.Controller
+import play.api.mvc.Result
+import models.com.hascode._
+
+object Data extends Controller {
+  val bookForm: Form[Book] = Form(mapping("title" -> text, "author" -> text)(Book.apply)(Book.unapply))
+
+  def test = Action {
+    Ok(views.html.myform(bookForm))
+  }
+
+  def post = Action { implicit request =>
+    val book = bookForm.bindFromRequest.get
+    Ok("post")
+  }
+}

File app/models/com/hascode/Book.scala

+package models.com.hascode
+
+case class Book(title: String, author: String)

File app/views/myform.scala.html

+@(bookForm:Form[models.com.hascode.Book])
+<h1>Le data</h1>
+
+@bookForm.render()
 GET     /assets/*file               controllers.Assets.at(path="/public", file)
 
 # JSON test
-GET     /json                           controllers.Application.jsonData
+GET     /json                           controllers.Application.jsonData
+
+# form example
+GET     /data/test                  controllers.Data.test()
+GET     /data/post                  controllers.Data.post()