如何将windows.alert替换为sweetalert?

时间:2018-02-04 09:31:59

标签: javascript php jquery

<form class="w3-container" form method="POST" action="login.php" autocomplete="off">
        <div class="w3-section">
            <label><b><i class="fa fa-user"></i> Username</b></label>
            <input class="w3-input w3-border w3-margin-bottom" type="text" placeholder="Enter Username" name="username" required>
            <label><b><i class="fa fa-unlock-alt" id="iconcart"></i> Password</b></label>
            <input class="w3-input w3-border" type="password" placeholder="Enter Password" name="password" required>
            <button class="w3-button w3-block w3-green w3-section w3-padding" type="submit">Login</button>
            <input class="w3-check w3-margin-top" type="checkbox" checked="checked"> Remember me
        </div>
    </form>








 if ($_SERVER["REQUEST_METHOD"] == "POST") {
        $username=check_input($_POST['username']);

        if (!preg_match("/^[a-zA-Z0-9_]*$/",$username)) {
            ?>  
            <script>
                window.alert('Username should not contain space and special characters!');
                window.history.back();
            </script>
        <?php
        }
        else{

        $fusername=$username;

        $password = check_input($_POST["password"]);
        $fpassword=md5($password);

        $query=mysqli_query($conn,"select * from `user` where username='$fusername' and password='$fpassword'");

        if(mysqli_num_rows($query)==0){
            ?>

            <script>
                    window.alert('Login Failed, Invalid Username or Password!');
                    window.history.back();
                </script>

1 个答案:

答案 0 :(得分:0)

window.alert=function(event) {
    event.preventDefault();
    /* Your Sweetalert code here */  
}