I am trying to create a validation using express-validation but I am having a syntax error in my html page
I would appreciate If anyone can give me a clue on the issue I encounter.
SyntaxError: Unexpected token ) in /Users/johnmichaelquintero/Projects/rateme/views/user/signup.ejs while compiling ejs. If the above error is not helpful, you may want to try EJS-Lint: https://github.com/RyanZim/EJS-Lint
signup.ejs
<% if(hasErrors) {%> <% for(var i=0; i < messages.length; i++) {%> <div class="alert alert-danger"> <a href="" class="close" data-dismiss="alert" aria-label="close"> &time; </a> </div> <%= messages[i] =%> <% } %> <% } %>
user.js:
app.get('/signup', (req, res) => {
var errors = req.flash('error'); //to get the error message
console.log(errors);
res.render('user/signup', {title: 'Signup || RateMe', messages: errors, hasErrors: errors.Length > 0});
});
The issue is with the =%>
after messages[i]
. There should not be an equal sign there.
This should work:
<% if(hasErrors) {%>
<% for(var i=0; i < messages.length; i++) {%>
<div class="alert alert-danger">
<a href="" class="close" data-dismiss="alert" aria-label="close">
&time;
</a>
</div>
<%= messages[i] %>
<% } %>
<% } %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.