doujuncuo9339 2015-10-09 21:40
浏览 33
已采纳

如何在登录失败后保持模态窗口打开?

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.

  • 写回答

1条回答 默认 最新

  • dongmu3187 2015-10-09 21:45
    关注

    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/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办