【问题标题】:Load a Bootstrap modal if a session exists is not working如果会话存在不工作,则加载引导模式
【发布时间】:2019-11-16 12:57:35
【问题描述】:

嗨,正如标题所示,如果页面加载时存在会话,我想加载一个模式弹出窗口。 如果我删除 php 的条件,模态将显示:

<?php if (!empty($_SESSION["ErreurLogin"])) { ?>
    <script>
        ...
    </script>
  <?php } ?>

但是,如果我添加它,则不会显示 Modal。如果我只想将会话的值显示在模态上,则模态显示没有值! ????。

这是脚本:

<?php if (!empty($_SESSION["ErreurLogin"])) { ?>
    <script>
    // I tried both
        // $(document).ready(function () {
        //     $('#mmodal').modal('show');
        // });
    // and 
        $( "#mmodal" ).load(function() {
          $('#mmodal').modal('show');
        });
    </script>
  <?php } ?> 

这是引导模式

<!-- Large modal -->

<div class="modal fade bd-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true" id="mmodal">
  <div class="modal-dialog modal-lg mt-5" style="margin-top: 0;">
    <div class="modal-content">
      <form class="form"  method="post" action="Function/F_Login.php" autocomplete="off" id="my_form">
          <div class="card-body" style="padding-left: 9%;padding-right: 10%;">
              <div class="form-group bmd-form-group">
                  <div class="input-group">
                    <div class="input-group-prepend">
                      <div class="input-group-text"><i class="fas fa-user"></i></div>
                    </div>
                    <input type="email" name="user" class="form-control" placeholder="Nom d'utilisateur...">
                  </div>
              </div>

              <div class="form-group bmd-form-group">
                  <div class="input-group">
                    <div class="input-group-prepend">
                      <div class="input-group-text"><i class="fas fa-lock"></i></div>
                    </div>
                    <input type="password" name="pass" placeholder="mot de passe..." class="form-control">
                  </div>
              </div>
              <h6 class="text-danger"><?php if(!empty($_SESSION["ErreurLogin"])){echo $_SESSION["ErreurLogin"];}?><?php unset($_SESSION["ErreurLogin"]); ?></h6>

          </div>

          <div class="modal-footer justify-content-center p-0">
              <a class="btn btn-link btn-wd btn-lg" href="javascript:{}" onclick="document.getElementById('my_form').submit(); return false;">Commencer</a>
          </div>
      </form>
    </div>
  </div>
</div>

【问题讨论】:

    标签: javascript php sql-server bootstrap-modal


    【解决方案1】:

    你可以试试这个

    <?php if (!empty($_SESSION["ErreurLogin"])) { ?>
    

    <div class="modal fade bd-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true" id="mmodal">
      <div class="modal-dialog modal-lg mt-5" style="margin-top: 0;">
        <div class="modal-content">
          <form class="form"  method="post" action="Function/F_Login.php" autocomplete="off" id="my_form">
              <div class="card-body" style="padding-left: 9%;padding-right: 10%;">
                  <div class="form-group bmd-form-group">
                      <div class="input-group">
                        <div class="input-group-prepend">
                          <div class="input-group-text"><i class="fas fa-user"></i></div>
                        </div>
                        <input type="email" name="user" class="form-control" placeholder="Nom d'utilisateur...">
                      </div>
                  </div>
    
                  <div class="form-group bmd-form-group">
                      <div class="input-group">
                        <div class="input-group-prepend">
                          <div class="input-group-text"><i class="fas fa-lock"></i></div>
                        </div>
                        <input type="password" name="pass" placeholder="mot de passe..." class="form-control">
                      </div>
                  </div>
                  <h6 class="text-danger"><?php if(!empty($_SESSION["ErreurLogin"])){echo $_SESSION["ErreurLogin"];}?><?php unset($_SESSION["ErreurLogin"]); ?></h6>
    
              </div>
    
              <div class="modal-footer justify-content-center p-0">
                  <a class="btn btn-link btn-wd btn-lg" href="javascript:{}" onclick="document.getElementById('my_form').submit(); return false;">Commencer</a>
              </div>
          </form>
        </div>
      </div>
    </div>
    
    <script type="text/javascript">
        $(window).load(function () {
            $('#myModal').modal('show');
        });
    </script>
    <?php } ?>

    这是我的工作及其与我的合作 首先,如果您不加载会话库,则必须将其加载到控制器中

     $this->load->library('session');
    

    第二次更改这一行

     $(window).load(function () 
    

    与

     $(window).on('load', function() {
                    $('#mmodal').modal('show');
                });
    

    【讨论】:

    • 是的,我做到了,但没有任何改变
    猜你喜欢
    • 1970-01-01
    • 2014-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多