0

Hello I'm figuring it out how to prevent from closing when validation errors. It seems that it refreshing due to "POST".

My html

 <div class="modal fade" id="popupmodal" role="dialog">
    <div class="modal-dialog">
        <div class="content" id="login">
            <?php
        if(isset($_GET['inactive']))
        { ?>
              <div class='alert alert-error'>
                <button class='close' data-dismiss='alert'>&times;</button>
                <strong>Sorry!</strong> This Account is not Activated Go to your Inbox and Activate it.
            </div>
            <?php
        }
        ?>
    <form class="form-signin" method="post">
        <?php
        if(isset($_GET['error']))
        {
            ?>
                 <div class='alert alert-success'>
                <button class='close' data-dismiss='alert'>&times;</button>
                <strong>Wrong Details!</strong>
            </div>
            <?php
        }
        ?>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <center><img src="images/infor-logo.png"</center>


        <h4 class="form-signin-heading" id="loginfont">Information Development</h4><hr />
        <input type="text" class="input-block-level" placeholder="Username" name="txtemail" required />
        <input type="password" class="input-block-level" placeholder="Password" name="txtupass" required />
        <hr />

        <button class="btn btn-large btn-primary" type="submit" name="btn-login">Sign in</button>

      </form>

    </div>
</div>
</div>

JS

 <script>
$(document).ready(function(){
    $("#login-popup").click(function(){
        $("#popupmodal").modal();
    });
});
</script>

PHP code

public function login($uname,$upass)
    {
        try
        {
            $stmt = $this->conn->prepare("SELECT * FROM users WHERE userName=:user_name");
            $stmt->execute(array(":user_name"=>$uname));
            $userRow=$stmt->fetch(PDO::FETCH_ASSOC);

            if($stmt->rowCount() == 1)
            {
                    if($userRow['password'] == $upass)
                    {
                        $_SESSION['userSession'] = $userRow['userID'];
                        return true;
                    }


                else
                {
                    header("Location: index.php?error");


                }
            }
            else
            {
                header("Location: index.php?error");


            }
        }
        catch(PDOException $ex)
        {
            echo $ex->getMessage();
        }
    }
Jeff
  • 6,895
  • 1
  • 15
  • 33
Robert
  • 13
  • 7

1 Answers1

0

You need to submit your form with AJAX request to server instead of synchronous request.

You can visit following link for your reference: How can I keep the modal window open after login failure?

Patrick R
  • 6,621
  • 1
  • 24
  • 27