i using the nodejs . i have a form for register .
this is my js code :
Register(req, res) {
res.render('auth/register', { messages: req.flash('errors') })
}
RegisterProcess(req, res) {
var validateResult = validationResult(req);
if (!validateResult.isEmpty()) {
const errors = validateResult.array();
let messages = [];
errors.forEach(error => {
messages.push(error.msg);
});
req.flash('errors', messages)
res.redirect('/auth/register');
}
}
and this is the ejs file :
<% if(messages.length > 0) { %>
<ul>
<% messages.forEach(err=>{ %>
<li><%- err %></li>
<% }) %>
</ul>
<% } %>
but it not show me any error .
i log the messages in the RegisterProcess and it return the errors in console but when i log in the Register it not show me any error in the console.
i console this in the Register Controller req.flash('errors') but it just show me the empty array [] .
whats the problem ? how can i solve this problem ???