0
nodejs/expressを使用してサインアップページを検証しようとしています。私が本当にしたいのは、req.validationErrors()
のエラーメッセージを私のフォームに表示することです。私はヒスイの代わりにEJSを使用しています、私は次のコードで.jadeを使用してエラーを表示する方法を説明しましたが、私は.ejsでエラーを表示する方法を知りたいです。ここでフォームにreq.validationErrorを表示する方法
はsignup.jadeでヒスイコードです:
ul.errors
if errors
each error, i in errors
li #{error.msg}
とも以下はuser.jsの中にフォームの検証コードです:
// Form Validation
req.checkBody('name', 'Name field is required').notEmpty();
req.checkBody('email', 'Email field is required').notEmpty();
req.checkBody('email', 'Email not valid').isEmail();
req.checkBody('username', 'Username field is required').notEmpty();
req.checkBody('password', 'Password field is required').notEmpty();
req.checkBody('password2', 'Passwords do not match').equals(req.body.password);
// Check for errors
var errors = req.validationErrors();
if (errors) {
res.render('register', {
errors: errors,
name: name,
email: email,
password: password,
password2: password2
});
} else {
var newUser = new User({
name: name,
email: email,
username: username,
password: password,
profileimage: profileImageName
});