Open modal after form Ubmit

Asked

Viewed 660 times

1

Good afternoon, I am developing a login system, that if the user enters the password or incorrect email, appears in a modal window that the data does not match the typed, but when the password or email are incorrectly typed, the modal window is not opening, causing the user to press the button to open it... But this message appears, I wonder how I can make the modal window can open..?

HTML:

            <div class="modal-body text-md-center">
      <form method="post" action="valida.php">
          <div class="form-row">
              <div class="form-group">

                  <input type="email" class="form-control" name="email" id="email" placeholder="Email:">
                  <input type="password" class="form-control" id="senha" name="senha" placeholder="Senha:">
                  <br>
              </div>
          </div>

          <input type="submit" name="btnLogin" value="Entrar" class="btn btn-outline-warning"><br><br>
          <?php
              if(isset($_SESSION['msg'])){
                echo $_SESSION['msg'];

              }
            ?>
          <p class="text-center">
              Caso não possuir conta, <a href="#cadastrouser"  data-toggle="modal" data-target="#modalSelecionar" data-dismiss="modal">cadastre-se</a>
          </p>
      </form>
          </div>

PHP:

    <?php
include("conexao.php");

$email = $_POST['email'];
$senha = $_POST['senha'];
/* Verifica se existe usuario, o segredo ta aqui quando ele procupa uma 
linha q contenha o login e a senha digitada */
$sql_logar = "SELECT * FROM aluno WHERE email = '$email' && senha = '$senha'";
$exe_logar = mysqli_query($conection, $sql_logar) or die (mysqli_error());
$fet_logar = mysqli_fetch_assoc($exe_logar);
$num_logar = mysqli_num_rows($exe_logar);

//Verifica se n existe uma linha com o login e a senha digitado
if ($num_logar == 0){
    session_start();
    $_SESSION['msg'] = "<div class='alert alert-danger'>Login ou senha incorreto!</div>";
    header("Location: index.php?login");

} 
else{
   //Cria a sessão e manda pra pagina principal.php
   session_start();
   $_SESSION['email'] = $email;
   $_SESSION['senha'] = $senha;
   header("Location:aluno.php");
}
?>

If anyone has an idea of what can be done, and can help, I will be grateful!

  • That one ?login in the URL of index.php is to identify which password or email was entered wrong?

  • No, this ? login directs when the user type wrong.. So when ? login appears I want it to be with the modal open..

  • Is this modal bootstrap? 3 or 4?

1 answer

1


As the parameter ?login is added to the URL when the user is redirected when he misses the login information, you can open the modal manually by identifying if the URL contains ?login with:

<?php
if(isset($_GET['login'])){
   // faz alguma coisa
}
?>

The if above will only be satisfied from in the URL you have ?login (or &login, if login is not the first parameter). Then instead of // faz alguma coisa you can carry a script to open the modal:

<?php
if(isset($_GET['login'])){
?>
<script>
document.addEventListener("DOMContentLoaded", function(){
   $('#ID_DA_MODAL').modal('show');
});
</script>
<?php
}
?>

In place of ID_DA_MODAL, you put the id of the modal that wants to open.

  • It worked Sam, thank you very much!! was missing the GET method with this script.. now I learned how it does.. Thanks a lot.!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.