这是我的scala模板代码:
@form(routes.Application.login) {
<div class="emailaddress">E-mail address:</div>
<div class="inputbox">
@helper.input(userForm("email"), '_id -> "email", '_label->"" ) { (id, name, value, args) =>
<input placeholder="Insert email" type="text" class="email-input" id="@id" name="@name" value="" @toHtmlArgs(args)>
}
</div>
<div class="password">Password:</div>
<div class="inputbox1">
@helper.input(userForm("password"), '_id -> "password", '_label->"") { (id, name, value, args) =>
<input placeholder="Insert password" class="password-input" type="password" id="@id" name="@name" value="" @toHtmlArgs(args)>
}
</div>
<div >
<button id="submit-button" class="myButton" >Submit</button>
</div>
@if(userForm.hasGlobalErrors) {
<div class="alert alert-error">
<a class="close" data-dismiss="alert">×</a>
function to javascriptPopUp(@userForm.globalError.get.message);
</div>
}
}
我的控制器代码是:
def login = Action { implicit request =>
userForm.bindFromRequest.fold(
errors=> BadRequest(views.html.user.userLogin(UserDB.findAll, errors)),
user => {
val use = UserDB.findUserByLogin(user.email, user.password)
if(use!=None){
Redirect(routes.DataManagementController.projects).withSession(Security.username -> user.email).flashing("success" -> "You've been logged in")
}else{
Ok(views.html.user.userLogin(UserDB.findAll, userForm))
}
}
)
}
但即使有错误,它也永远不会进入我的javascript函数。 任何人都可以向我解释为什么我永远不会进去吗?
(如果您需要更多代码,请问我会发布,我只是在此页面上节省空间,因为登录有效,我不能只显示消息错误。)