0

我在使用表单助手时遇到了问题。我想在将表单传递给视图之前向表单添加一个错误,但出现以下错误:

value withGlobalError is not a member of play.api.data.Form[(String, String)]  

我的代码如下:

def loginForm = Form(
            tuple (
              "email" -> nonEmptyText,
              "password" -> nonEmptyText
            )
    )   


def asignIn = Action {
      implicit request => 
        loginForm.bindFromRequest.fold (
              formWithErrors => Ok(views.html.login(formWithErrors.withGlobalError("Invalid username or password")),
              user => authenticationStep(user)(request)
      )
    }
4

1 回答 1

1

电子邮件和密码的验证应以如下形式完成:

val loginForm = Form(
  tuple(
    "email" -> nonEmptyText,
    "password" -> text
  ) verifying("Invalid user name or password", fields => fields match { 
      case (email, pwd) => User.authenticate(email,pwd).isDefined 
  })
)
于 2012-10-23T10:44:55.677 回答