【问题标题】:how to open a modal for several time after form submission表单提交后如何多次打开模态
【发布时间】:2018-06-27 16:30:39
【问题描述】:

在我的应用程序中,我有一个表单。在提交表单并重定向到下一页后,我想要一个模式几秒钟。但我无法做到这一点。

表格

<form method="post" action="topicadddb.php" >

                <div class="table-responsive table-bordered">
                            <table class="table">

                                <tbody>

                                     <tr>
                                        <td>
                                            <label>TOPIC</label>
                                        </td>
                                        <td>
                                            <input class="form-control" name="txttopicname">
                                        </td>
                                    </tr>



                                    <tr>


                                    <tr>
                                        <td colspan=3><button class="btn btn-success btn-lg btn-block" type="submit" >ADD TOPIC</button></td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
            </form>

topicadddb.php

<?php
session_start();


require_once("../../connectdb.php");     

$topicname  = $_POST['txttopicname'];

$s="INSERT INTO topicinfo (topicname,status) VALUES ( UPPER('$topicname'),0)";

//echo $s;

mysqli_query($conn,$s) or die( mysqli_error());
header('Location:topiclistdb.php');   

?>

当提交按钮单击模式打开几秒钟并重定向到下一页时,这是我想要的代码。请帮助我如何做到这一点。 谢谢

【问题讨论】:

    标签: javascript php jquery html mysqli


    【解决方案1】:

    首先创建一个模态,然后使用 SetTimeout 函数使其在特定时间出现。把这个放在重定向之前

        setTimeout(function(){
        $(dialog).close();
    }, 10000);
    

    【讨论】:

    • 我该怎么做?我不明白如何在哪个页面中进行模态调用。请给我一些详细信息。我希望在提交表单后在右上角显示一个小模态显示,例如重定向页面中的通知。
    • 等我分享js小提琴
    【解决方案2】:

    HTML 页面应该是 Like

     <form method="post" action="topicadddb.php" >
    
                    <div class="table-responsive table-bordered">
                                <table class="table">
    
                                    <tbody>
    
                                         <tr>
                                            <td>
                                                <label>TOPIC</label>
                                            </td>
                                            <td>
                                                <input class="form-control" name="txttopicname">
                                            </td>
                                        </tr>
    
    
    
                                        <tr>
    
    
                                        <tr>
                                            <td colspan=3><button class="btn btn-success btn-lg btn-block" type="submit" >ADD TOPIC</button></td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                </form>
    
            <?php $session_value=(isset($_SESSION['success']))?$_SESSION['success']:''; ?>
    
        <div id="myModal" class="modal">
          <div class="modal-content">
            <span class="close">&times;</span>
            <p>Some text in the Modal..</p>
          </div>
    
    </div>
    
    <script>
    var modal = document.getElementById('myModal');
    var span = document.getElementsByClassName("close")[0];
    span.onclick = function() {
        modal.style.display = "none";
    }
    window.onclick = function(event) {
        if (event.target == modal) {
            modal.style.display = "none";
        }
    }
    
    
    $(document).ready(function() {
    var = <?php echo $session_value; ?>
        if(var!=''){
        $("p").show();
            setTimeout(function(){
            $("p").hide();
        }, 3000);
        }
    });
    </script>
    

    PHP 页面将变为,

        <?php
        session_start();
    
    
        require_once("../../connectdb.php");     
    
        $topicname  = $_POST['txttopicname'];
    
        $s="INSERT INTO topicinfo (topicname,status) VALUES ( UPPER('$topicname'),0)";
    
        mysqli_query($conn,$s) or die( mysqli_error());
    $_SESSION['success'] ="success";
        header('Location:topiclistdb.php');   
    
        ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-06
      • 1970-01-01
      • 2011-02-02
      • 1970-01-01
      • 2016-07-03
      • 2017-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多