如何防止弹出模式在验证错误时关闭

时间:2018-02-01 02:25:50

标签: javascript php

您好我正在弄清楚如何在验证错误时阻止关闭。它似乎因“POST”而令人耳目一新。

我的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代码

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();
        }
    }

1 个答案:

答案 0 :(得分:0)

您需要将包含AJAX请求的表单提交给服务器而不是同步请求。

您可以访问以下链接供您参考: How can I keep the modal window open after login failure?