javascript - EJS IF statment error with Node JS MongoDB -
i trying have server side validation app as
node js view code
router.post('/', function(req, res, next) { var fullname = req.body.fullname; var email = req.body.email; var rollno = req.body.rollno; var birthdate = req.body.birthdate; var gender = req.body.gender; var password = req.body.password; var confirm = req.body.confirm; req.checkbody('fullname', 'name required').notempty(); req.checkbody('email' , 'email required').notempty(); req.checkbody('email' , 'invalid email').isemail(); req.checkbody('rollno', 'roll number required').notempty(); req.checkbody('birthdate', 'date of birth required').notempty(); req.checkbody('gender' , 'gender required').notempty(); req.checkbody('password' , 'password required').notempty(); req.checkbody('confirm' , 'password not matched').equals(req.body.password); var errors = req.validationerrors(); if (errors) { res.render('/signup' , { errors : errors }); } else { console.log('no errors'); }}); and ejs
<% if(errors){ %> <% errors.foreach(function(msg) { %> <div class="alert alert danger"><% msg %></div> <% }); %> <% } %> when try /sign method specified in other route file output ejs code in browser errors not defined message???
Comments
Post a Comment