如何使用模态获取多值复选框

时间:2019-05-09 11:56:03

标签: php html5 checkbox bootstrap-4 bootstrap-modal

单击提交时如何显示模态?

没有模态的输出是成功的,但是如果我使用模态弹出窗口,它什么也不显示。

这是我的身体html

<form action="" method="post">
        <div class="row">
            <div class="offset-4 col-sm-8 mt-5">
                <input type="checkbox" name="hobby[]" value="Sepak Bola"> Sepak Bola <br>
                <input type="checkbox" name="hobby[]" value="Membaca"> Membaca <br>
                <input type="checkbox" name="hobby[]" value="Menulis"> Menulis <br>
                <input type="checkbox" name="hobby[]" value="Memancing"> Memancing <br>
            </div>
        </div>
        <div class="row">
            <div class="offset-5 col-sm-7">
                <input type="submit" name="proses" class="btn btn-primary" value="Proses" data-toggle="modal" data-target="#exampleModal">
            </div>
        </div>
    </form>

这是我的模特表演:

 <!-- AWAL MODAL -->
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="offset-4 col-sm-8 mt-5">
                            <h3>OUTPUT : </h3>
                            <?php
                            if (isset($_POST['proses'])) :
                                if (!empty($_POST['hobby'])) :
                                    foreach ($_POST['hobby'] as $selected) :
                                        echo $selected . "</br>";
                                    endforeach;
                                endif;
                            endif;
                            ?>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                </div>
            </div>
        </div>
    </div>
    <!-- AKHIR MODAL -->

我的模态只是不提交信息

1 个答案:

答案 0 :(得分:3)

好吧,如您所愿,这是显示值的模式:

    //Declare the jquery param on top after import
declare var $: any;
declare var jQuery: any;

clearForm() {
    $('#contactForm')[0].reset();
}