title: How to correctly validate forms with Play! in Scala?
body: <p>I'm brand new to Play!, and I'm trying to migrate my existing website from cakePHP to Play!.</p>
  
  <p>The problem I'm facing is about form validation.</p>
  
  <p>I defined a case class User, representing the users of my website :</p>
  
  <pre><code>case class User(
    val id: Long,
    val username: String,
    val password: String,
    val email: String
    val created: Date)
  </code></pre>
  
  <p>(There are some more fields, but these ones suffice to explain my problem)</p>
  
  <p>I would like my users to be able to create an account on my website, using a form, and I would like this form to be validated by Play!.</p>
  
  <p>So, I created the following action :</p>
  
  <pre><code>def register = Action {
    implicit request =&gt;
  
      val userForm = Form(
        mapping(
          "id" -&gt; longNumber,
          "username" -&gt; nonEmptyText(8),
          "password" -&gt; nonEmptyText(5),
          "email" -&gt; email,
          "created" -&gt; date)(User.apply)(User.unapply))
  
      val processedForm = userForm.bindFromRequest
      processedForm.fold(hasErrors =&gt; BadRequest("Invalid submission"), success =&gt; {
        Ok("Account registered.")
      })
  }
  </code></pre>
  
  <p>Obviously, I do not want the user to fill the id or the creation date by himself in the form. So my question is : <strong>what should I do ?</strong></p>
  
  <p>Should I define a new "transition model" containing only the fields that are actually provided to the user in the form, and transform this intermediary model into the complete one before inserting it into my database ?</p>
  
  <p>That is, replace my action by something like that :</p>
  
  <pre><code>def register = Action {
    implicit request =&gt;
  
      case class UserRegister(
        username: String,
        password: String,
        email: String)
  
      val userForm = Form(
        mapping(
          "username" -&gt; nonEmptyText(8),
          "password" -&gt; nonEmptyText(8),
          "email" -&gt; email)(UserRegister.apply)(UserRegister.unapply)
  
      val processedForm = userForm.bindFromRequest
      processedForm.fold(hasErrors =&gt; BadRequest("Invalid submission"), success =&gt; {
        val user = User(nextID, success.username, success.password, success.email, new Date())
        // Register the user...
        Ok("Account created")
  }
  </code></pre>
  
  <p>Or is there another, cleaner way to do what I want ?</p>
  
  <p>I've been through many tutorials and the book "Play for Scala", but in the only examples that I found, the models were fully filled by the forms... I really like Play! so far, but it looks like the documentation often lacks examples...</p>
  
  <p>Thank you very much for your answers !</p>