Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

407
Views
Why when something is wrong in inputs the errors doesn't display

I made a register page using node js and I made some validations as an example if password doesn't match with confirm the passwords it returns back to the signup page and listing the errors beneath the the (h1) tag which is sign up but it's returns back to the sign page without any errors here's my code:

module.exports.signup_post = (req,res)=>{
let {firstName,lastName,username,email,password,password2} = req.body;
console.log(
    firstName,
    lastName ,
    username,
    email,
    password,
    password2
    );

let errors =[];

if (!firstName || !lastName || !username || !email || !password || !password2){
    errors.push({message:'please enter the all fields'});

}
if (password.length<6){
    errors.push({message:'password should be at least 6 characters'})
}
if (password!= password2){
    errors.push({message:'passwords do not match'})
}
if (errors.length > 0){
    res.render('register');
    
}else{
    res.render('login')
  }

}


<ul>
        <% if (typeof errors != 'undefined'){ %>
            <% errors.forEach(error =>{ %>
                <li><% error.message %></li>
                <% }) %>
            <% } %>
    </ul>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Change the fifth line from the bottom to:

res.render("register", { errors: errors });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!