简体   繁体   English

如果 session 存在,则加载引导模式不起作用

[英]Load a Bootstrap modal if a session exists is not working

Hi as the title suggests I would like to load a modal popup if a session exists on page load.嗨,正如标题所示,如果页面加载时存在 session,我想加载一个模式弹出窗口。 the modal is showing if i remove the condition of php which is:如果我删除 php 的条件,则显示模式:

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

However, if I add it, the Modal is not displayed.但是,如果我添加它,则不会显示模态。 If i want only the value of the session to be displayed on the Modal, the Modal are shown without the value.如果我只想将 session 的值显示在模态上,则模态显示没有值。 . .

this is the script:这是脚本:

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

this's the Bootstrap Modal这是引导模式

<!-- 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>

You can try this你可以试试这个

<?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 } ?>

Here what i do and its work with me first if you dont load session library you must load it in controller如果您不加载 session 库,我首先要做什么及其与我一起工作,您必须将其加载到 controller

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

Second change this line二改这一行

 $(window).load(function () 

with

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM