如何以游戏形式添加验证?
下面是重置密码表格,要求用户输入两次密码。
@(tokenId: String, form: Form[ResetPassword])(implicit messages: play.api.i18n.Messages, request: RequestHeader)
@main("Reset Password") {
@helper.form(routes.Application.handleResetPassword(tokenId)) {
@helper.inputText(form("password1"))
@helper.inputText(form("password2"))
<button type="submit">Submit</button>
}
}
在上面的表格中,我想添加验证,检查密码1和密码2是否相同。
由于 彩
答案 0 :(得分:1)
你可以这样做:
val userFormConstraintsAdHoc = Form(
mapping(
"password1" -> text,
"password2" -> text
)(UserData.apply)(UserData.unapply) verifying("Failed form constraints!", fields => fields match {
case userData => form.password1.equals(form.password2)
})
)
这只是未经测试的伪代码,请查看docs for that purpose