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

92
Visualizações
Add class in HTML with PHP

I have a form with email and password validation. When password is wrong the box password has to be red to show that something go wrong, i do that adding a "vermei" class.

I have to do this in PHP, already attempted:

$dom=new DOMDocument;
$dom->loadHTML($html);
$input=$dom->getElementById('password');
foreach($input as $pd){
    $pd->setAttribute('class', $pd->getAttribute('class').' vermei');
}
$html = $dom->saveHTML(); // return 'variable $html not found'

and

echo '<script>
        alert("Password Incorrect!");
        history.go(-1); //work until this part, the code below do not run. 
 //I did this go back cuz when form is submitted, go to config.php, and
 // this code back to sign in page
        var password = document.getElementById("password");
        document.getElementById("password").focus();
        password.classList.add("vermei");
    </script>';

Someone can help me with adding a "vermei" class in Password input?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your first code doesn't work because $input is a single element, not a list, so you can't loop over it. Replace the loop with just:

$input->setAttribute("class", $input->getAttribute("class") . " vermei");

Normally you would do this in the code that outputs the form, e.g.

<form>
    ...
    Password: <input id="password" type="password" name="password" <?php if ($password_incorrect) echo 'class="vermei"'; ?>>
    ...
</form>
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