简体   繁体   English

如何使用不同的 PHP 值打开引导模式

[英]how to open bootstrap modal with different PHP value

i have a php app with 3 table, each one have multiple row with button for each row to get a form for the affected data我有一个带有 3 个表格的 php 应用程序,每个表格都有多行,每行都有按钮,以获取受影响数据的表格

the idea is to give a value for the modal to have as much column as in the affected table.这个想法是为模式提供一个值,使其具有与受影响的表中一样多的列。

until now, i tried to have one form with button fo each table, with different value, and testing it in php to use the correct table for for the column as below in the code (it's a test webpage so there is just one button, i'm just trying to open a modal manually after testing a php value ):到目前为止,我尝试为每个表创建一个带有按钮的表单,具有不同的值,并在 php 中对其进行测试,以便在代码中使用正确的表作为下面的列(这是一个测试网页,所以只有一个按钮,我只是在测试 php 值后尝试手动打开模式):

<body>
<form action="" method="post">
    <button type="submit" class="btn btn-primary" data-bs-toggle="modal" data-bs- 
        target="#CreateInfra" name="der">
        Launch demo modal
    </button>
</form>
<script>
    function modal(){
            $("#myModal").modal('show');
    }
</script>
<div class="bs-example">
    <!-- Modal HTML -->
    <div id="myModal" class="modal fade" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Modal Title</h5>
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                </div>
                <div class="modal-body">
                    <p>This is a simple Bootstrap modal. Click the "Cancel button", "cross icon" or 
                    "dark gray area" to close or hide the modal.</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data 
                        dismiss="modal">Cancel</button>
                    <button type="button" class="btn btn-primary">Save</button>
                </div>
            </div>
        </div>
    </div>
</div>
    <?php
    if (isset($_POST['der'])){
        $value = 1;
        var_dump($value);
    }
    else{
        $value=2;
        var_dump($value);
    }

    if ($value == 1){
        echo "<script>modal()</script>";

    }
    ?>

</body>

the thing is, when i hit the button, i see my page loading something for maybe 0.4 second but nothing happen.问题是,当我按下按钮时,我看到我的页面加载了大约 0.4 秒的内容,但没有任何反应。

is there any way to do this or i should use something else?有什么办法可以做到这一点,或者我应该使用别的东西吗?

You can do something like this as long as you want it to decide on the page load只要您希望它决定页面加载,您就可以执行此类操作

<script>
    function modal(val){

        let options = [];
        var myModal = new bootstrap.Modal(document.getElementById('exampleModal'))

        if (val == 0){
            myModal.show()
        }
    }
</script>
<?php $val = 0; ?>
<?php echo "<script>modal(".$val.")</script>" ?>

Other than that you would have to do it through a fetch request or AJAX because php and JS can't directly talk to each other除此之外,您必须通过获取请求或 AJAX 来完成,因为 php 和 JS 不能直接相互交谈

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

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