0

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 ???

1 Answer 1

0

change this <li><%- err %></li>

to <li><%= - err %></li>

Sign up to request clarification or add additional context in comments.

1 Comment

While this code may resolve the OP's issue, it is best to include an explanation as to how your code addresses the OP's issue. In this way, future visitors can learn from your post, and apply it to their own code. SO is not a coding service, but a resource for knowledge. Also, high quality, complete answers are more likely to be upvoted. These features, along with the requirement that all posts are self-contained, are some of the strengths of SO as a platform, that differentiates it from forums. You can edit to add additional info &/or to supplement your explanations with source documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.