我正在尝试验证电子邮件是否有效。这是我想要做的:
private val emailForm =
Form(mapping("id" -> optional(of[Long]), "email" -> email)(Email.apply _)(Email.unapply _))
def submit = Action { implicit request =>
emailForm.bindFromRequest.fold(
formWithErrors => { // this code is never hit, even if I leave the textbox blank
Ok(views.html.masterpage("Home")(views.html.landingPage(formWithErrors, "There was an error on your form")))
}, email => {
emailDAO ! EmailDAO.Create(email)
Ok(views.html.masterpage("Thank you")(views.html.thankyou("Thank you for subscribing to our mailing list!")))
})
}
答案 0 :(得分:1)
我相信......您需要在表单定义中添加验证。
private val emailForm = Form(
mapping(
"id" -> optional( of[ Long ] ),
"email" -> email.verifying( emailAddress )
)( Email.apply _ )( Email.unapply _ )
)