Azuken
Azuken

Reputation: 487

Get all fields in a scala form

I make a form in scala with Play 2 framework, and I've a problem to get all fields : Before I tested with only 2 fields, so it works :

def subscription = Action {
  implicit request =>
  signForm.bindFromRequest.fold(
    errors => BadRequest,
    {        
      case (username, password) =>

        User.create(User(username, password))
        Ok(views.html.index(userForm, "visible", "User created."))
    }
  )
}

But when I want to have more than 2 fields, it doesn't work :

def subscription = Action {
  implicit request =>
  signForm.bindFromRequest.fold(
    errors => BadRequest,
    {        
      case (username, password, firstname, lastname, company) =>

        User.create(User(username, password, firstname, lastname, company))
        Ok(views.html.index(userForm, "visible", "User created."))
    }
  )
}

It show me : constructor cannot be instantiated to expected type; found : (T1, T2, T3, T4, T5) required: (String, String)

I understand that case() cannot have more than two parameters, but how I can get the other fields in this case ?

Upvotes: 0

Views: 235

Answers (1)

Jason
Jason

Reputation: 61

The answer to the problem is in the error message. Your form signForm is defined as a (String, String) and you need to extend it to include the additional fields. If you include the code for your form, a more detailed answer can be given.

Upvotes: 2

Related Questions