Using Jquery on a PHP page is it possible?

1

I have a Login page, which has a form, which sends the data of two fields (username and password) to a PHP file that performs the verification. This php file uses a function already written to a class. In this function, if the result is true, a redirect happens, otherwise it will execute a Jquery code to display an "Invalid Password" message on the login page. The intention is for this Jquery to change ownership of a certain element from "hidden" to "visible", thus displaying the message on the screen.

I'm a little confused, and I've never gotten right with jQuery, nor do I know if I'm forgetting some important detail, so I'd like a good soul to give me a help. HTML:

<?php
header("Content-Type: text/html; charset=ISO-8859-1", true);
?>
<!DOCTYPE html>
<html lang="pt-br">
    <head>
        <title>Login</title>
        <meta http-equiv="content-Type" content="text/html; charset=iso-8859-1" /> 
        <link rel="stylesheet" type="text/css" href="css/login_style.css">
    </head>
    <body>
        <div class="login-page">
            <div class="form">
                <form class="login-form" action="verificacaologin.php" method="post">
                    <input type="text" placeholder="Usuário" name="nome_usuario"/>
                    <input type="password" placeholder="Senha" name="senha"/>
                    <button type="submit">login</button>
                </form>
                <label class="senha_incorreta">Senha incorreta.Tente novamente.</label>
            </div>
        </div>
    </body>
</html>

Php that checks:

<?php
include_once 'classes/Usuario.php';

$nome = $_POST['nome_usuario'];
$senh = $_POST['senha'];

$usuario = new Usuario();

$usuario->verificarExistenciaLogin( $nome , $senh);
?>

Function of the User class that contains Jquery:

public function verificarSenhaCorreta( $nome_usuario , $senha )
{
    $query = "select SENHA from portfolio.usuario where NOME_USUARIO = '$nome_usuario' ";
    $conexao = new Conexao();
    $resultado_consulta = $conexao->abrirConexao( $query );

    $resultado_consulta = implode($resultado_consulta);

    if( $resultado_consulta == $senha )
    { 

          header("Location:ordem_servico.php");
    }
    else
    {
        //mostrar mensagem de que a senha está incorreta();

        ?>
        //Aqui que minhas dúvidas começam
        <script>

        $(document).ready(function()
        {
            $('.senha_incorreta').css( "visibility" , "visible" );
        });

        </script>
        <?php
    }
}
    
asked by anonymous 30.03.2018 / 21:42

2 answers

0

Create a function outside of PHP, along with your php, in this template:

    <body>
    ... conteudos php, html e etc
     <script>

           function exibeMensagemErro() {
                $('.senha_incorreta').css( "visibility" , "visible" );
}

            </script>
    </body>

and on your else, do:

echo "<script>exibeMensagemErro()</script>";
    
30.03.2018 / 22:13
0

From what I saw in your code you did not refer the JQuery file inside HTML .

I believe that when it does this will work, otherwise, it tries to query through the onclick() event of button using Ajax that will wait for the response from PHP > and thus enable or disable the label .

    
30.03.2018 / 23:08