登录失败后如何保持模态窗口打开? [英] How can I keep the modal window open after login failure?

查看:22
本文介绍了登录失败后如何保持模态窗口打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用引导程序,我打开了一个用于从导航栏登录的模式窗口.如果登录凭据失败,则模式将消失,就像凭据成功时一样.在运行完 PHP 验证过程后,如何让模式重新出现以供用户再次尝试登录?非工作相关代码是:

PHP 验证码:

<?phpif(PassHash::check_password($row["password"], $_POST['pwd1']))$_SESSION["登录"] = 1;$_SESSION['btnhs'] = 3;} 别的 {$_SESSION["登录"] = 0;$loginErr ="用户名或密码不正确.";?><script type="text/javascript">$(函数(){$('#myModal').modal('show');});<?php}

HTML:

<div class="modalfade" tabindex="-1" id="myModal" role="dialog" data-backdrop="static"><div class="modal-dialog" data-backdrop="static"><!-- 模态内容--><div class="modal-content"><div class="modal-header" style="padding:35px 50px;"><button type="button" class="close" data-dismiss="modal">&times;</button><h4><span class="glyphicon glyphicon-lock"></span>登录

<div class="modal-body" style="padding:40px 50px;"><form method="post" autocomplete="on" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"><div class="form-group"><label for="usrname"><span class="glyphicon glyphicon-user"></span>用户名</label><input type="text" class="form-control" required="" name="uname" id="uname" autofocus="" placeholder="输入用户名">

<div class="form-group"><label for="psw"><span class="glyphicon glyphicon-eye-open"></span>密码<input type="password" class="form-control" required="" name="pwd1" id="pwd1" placeholder="输入密码"><span class="error" style="color: red"><?php echo $loginErr;?></span><br>

<div class="form-actions"><button type="submit" name="login" class="btn btn-success btn-block"><span class="glyphicon glyphicon-log-in"></span>登录

</表单>

我试图在登录时从不成功的密码中调用 javascript 代码段,但这不起作用.任何人都可以看到这有什么问题并提供解决方案吗?谢谢.

解决方案

您正在同步提出您的请求.如果要保持模态打开,则需要向服务器发出 AJAX 请求,而不是完全提交表单.例如,对于 jQuery,您可以使用: http://api.jquery.com/jquery.post/

Using bootstrap, I have a modal window open for login purposes from the Navbar. If the login credentials fail, the modal disappears the same as it does if the credentials were successful. How, after running through the PHP validation process, can I make the modal reappear for the users to attempt login again? The non-working relevant code is:

PHP Validation code:

<head>
<?php
if(PassHash::check_password($row["password"], $_POST['pwd1']))
 $_SESSION["login"] = 1;
 $_SESSION['btnhs'] = 3; 
} else {
 $_SESSION["login"] = 0;
 $loginErr ="Username or password incorrect.";
?> 
 <script type="text/javascript">
  $(function() {
   $('#myModal').modal('show');
  });
 </script>                          
<?php
}
</head>

HTML:

<!-- Modal -->
  <div class="modal fade" tabindex="-1" id="myModal" role="dialog" data-backdrop="static">
    <div class="modal-dialog" data-backdrop="static">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header" style="padding:35px 50px;">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4><span class="glyphicon glyphicon-lock"></span> Login</h4>
        </div>
        <div class="modal-body" style="padding:40px 50px;">
            <form method="post"  autocomplete="on" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
            <div class="form-group">
              <label for="usrname"><span class="glyphicon glyphicon-user"></span> Username</label>
              <input type="text" class="form-control" required="" name="uname" id="uname" autofocus="" placeholder="Enter username">
            </div>
            <div class="form-group">
              <label for="psw"><span class="glyphicon glyphicon-eye-open"></span> Password</label>
              <input type="password" class="form-control" required="" name="pwd1" id="pwd1" placeholder="Enter password">
              <span class="error" style="color: red"><?php echo $loginErr;?></span><br>
            </div>
            <div class="form-actions">
              <button type="submit" name="login" class="btn btn-success btn-block"><span class="glyphicon glyphicon-log-in"></span> Login</button>
            </div>
         </form>
        </div>

I'm trying to call the javascript snippet from an unsuccessful password at login, but this isn't working. Can anyone see what is wrong with this and offer a solution? Thanks.

解决方案

You are making your request synchronously. If you want to keep modal open, you need to make AJAX request to server and not fully submit the form. For example, with jQuery you can use this: http://api.jquery.com/jquery.post/

这篇关于登录失败后如何保持模态窗口打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆