Playframework 2.0 播放框架:带有全局错误的窗体
我在使用表单助手时遇到困难。我想在将表单传递到视图之前向表单中添加一个错误,但出现以下错误:Playframework 2.0 播放框架:带有全局错误的窗体,playframework-2.0,Playframework 2.0,我在使用表单助手时遇到困难。我想在将表单传递到视图之前向表单中添加一个错误,但出现以下错误: value withGlobalError is not a member of play.api.data.Form[(String, String)] 我的守则如下: def loginForm = Form( tuple ( "email" -> nonEmptyText, "password" ->
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)
)
}
电子邮件和密码的验证应以如下形式进行:
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
})
)
我之所以不这样做,是因为我无法从
authenticate
返回的对象返回id
。如果您想要id
,可以在asignIn
函数中使用从loginForm
中获得的值来获取它。因此asignIn
中的user
包含我的对象根据我的测试,它包含元组(电子邮件、密码)。您建议我这样做的方式需要发出两次相同的请求。是的,它只包含元组(电子邮件,密码)
,并且正如您所说的,发出另一个请求,使用电子邮件获取您的对象。这不是在浪费请求吗?如果我能将与globalerror一起使用
,我只能执行一次请求。但我不确定上面列出的错误。