簡體   English   中英

使用引導模態進行確認后,PHP isset無法在表單提交上使用

[英]PHP isset not working on form submit after confirmation using bootstrap modal

我有一個帶有多個提交按鈕的表單,如下所示:

<form action="insert_data" method="post" id="topSubmit">
    <input type="checkbox" name="stories[]" id="stories" value="A">
    <input type="checkbox" name="stories[]" id="stories" value="B">
    <input type="checkbox" name="stories[]" id="stories" value="C">
    <!--   more checkboxes    -->
    <button class="btn btn-danger" type="submit" name="trunc-trend" id="trunc-trend" data-toggle="modal" data-target="#modal-trunc-trend">
        Add Stories 1
    </button>
    <button class="btn btn-danger" type="submit" name="trunc-top" id="trunc-top" data-toggle="modal" data-target="#modal-trunc-top">
        Add Stories 2 
    </button>
</form>

對於每個提交按鈕,都有一個確認模式(引導程序) ,如下所示:

<div class="modal fade" id="modal-trunc-trend" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <h4 style="text-align: center;">Are you sure to do this action ?</h4>
                </div>

                <div class="form-group" style="text-align: center;">
                    <button type="button" name="ensure-trunc-trend" id="ensure-trunc-trend" class="btn btn-success" style="margin-right: 15px">Yes</button>
                    <button type="button" class="btn btn-success" data-dismiss="modal">No</button>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>

    </div>
</div>

以下是我的jQuery代碼,其中,我首先阻止頁面在點擊“提交”按鈕時加載,這樣它就不會在確認之前從提交,如下所示:

$('#trunc-trend').click(function(e){
            e.preventDefault();
});

然后,在引導程序模版中單擊“ 是”按鈕后,即: <button type="button" name="ensure-trunc-trend" id="ensure-trunc-trend" class="btn btn-success" style="margin-right: 15px">Yes</button>

以下jQuery執行:

$('#ensure-trunc-trend').click(function(){
    $('#topSubmit').submit();
});

這將帶我進入下一個php頁面。 在此php頁面中,表單中的每個Submit按鈕都有一些isset條件。 但是這些問題條件不起作用。

這是我的php文件:

if (isset($_POST['trunc-trend'])) {
    echo "coming here.";
}

elseif (isset($_POST['trunc-top'])) {
    echo "this is working";
}

你知道這種病情如何可能起作用嗎?

變量$_POST['trunc-trend']$_POST['trunc-trop']來自兩個不同的提交按鈕,但是您是通過形式提交表單( $('#topSubmit').submit(); )。 提交輸入僅在單擊時發送,因此您的PHP腳本不會接收它們。

如果您嘗試這樣做:

$('#ensure-trunc-trend').click(function(){
        $('button[name=trunc-trend]').click();
});

您將獲得truc-trend變量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM