Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

408
Visualizações
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 Respostas
Responde à pergunta

0

Change the fifth line from the bottom to:

res.render("register", { errors: errors });
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda