bootstrap 确认后未提交表单

Form not submitting after bootstrap confirmation

首先,我会道歉,我对 jquery/javascript 的了解不是很好,所以我的错误对某些人来说可能很明显,但我仍在学习,所以请保持温和!

我有一个表单,允许成员删除他们从数据库中发布的帖子。该表单工作正常,使用 php 可以根据需要从数据库中删除数据。我想创建一个弹出窗口,让用户确认这就是他们想要做的。我不想使用沼泽标准浏览器特定的 onclick 方法我想要一些更可定制的东西。所以我正在尝试使用 bootbox,我目前有确认框弹出 onclick 但是当你 select 是时,没有其他事情发生。我怀疑 jquery 的结果没有触发表单,但从我阅读的那部分代码来看是好的?

我已经在我的 php、jquery 和 html

下面粘贴了

PHP:

<?php
$deletepost = 'none';
$deleteposterror = 'none';

if(isset($_POST['delete'])) {

    $del_topic_id = $_POST['topic_id_value'];

    // sql to delete a record
    $pass_fail = "DELETE FROM topics WHERE topic_id ='$del_topic_id';";

    $pass_fail .= "DELETE FROM posts WHERE topic_id_post ='$del_topic_id'";

    if (mysqli_multi_query($conn, $pass_fail)) {

    $deletepost = 'show';

    }else{

    $deleteposterror = 'show';
    echo "ERROR: Could not able to execute $pass_fail. "  . mysqli_error($conn);    

    }

}
?>

HTML & PHP 在 while 循环中:

<?php


            $sql1 = "SELECT * FROM topics WHERE topic_by = '".$id."' ORDER BY topic_date DESC ";
            $result1 = mysqli_query($conn, $sql1);

            while($row = $result1->fetch_assoc()) {

            $topic_id = $row ['topic_id'];
            $topic_subject = $row ['topic_subject']; 
            ?>



            <div class='chat_post_titles' >
            <div class='row'>
            <div class='col-md-7 chat_post_text_align_left'>
            <a href="../Chat/post.php?topic_id=<?php echo $topic_id?>"><?php echo $topic_subject?>.</a>
            </div>
            <div class='col-md-2 chat_post_text_align_right'>
            <?php
            $my_date = $row['topic_date'];
            $date = DATE("G:i:s d/m/Y",strtotime($my_date));
            ?>
            <div class='hide_text'>Post Date: </div>
            <?php echo $date?>
            </div>
            <div class='col-md-2 chat_post_text_align_centre'>
            <div class='hide_text'>Delete Post: </div>

            <form method="post" class="delete_post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
            <input type="hidden" name="topic_id_value" id="topic_id_value" value="<?php echo $topic_id?>">
            <button type="submit" name="delete" id="delete" class="btn btn-danger buttonElement">Delete</button>
            </form>
            </div>
            </div>
            </div>
            <?php
            }
            ?>

JQUERY 在页面底部:

</body>
<?php include("../PHP/js.php"); ?>
<script type="text/javascript" src="../Members/updatedetails.js"></script>
<script type="text/javascript" src="../Members/bootbox.min.js"></script>
<script>

$('form').on('click','button.buttonElement',function (e) {
    var form = $(this).closest('form'); // <-- add this

    e.preventDefault();

    bootbox.confirm({
        message: "Are you sure you want to delete your post?", 
        title: "Delete Post",
        buttons: {
            cancel: { 
                label: "No", 
                className: "btn btn-default"
            },
            confirm: { 
                label: "Yes", 
                className: "btn btn-default"
            }
         },
         callback: function(result) {
             if(result == true) {
                 form.submit();
             }
         }
    });
 });

</script>

</html>

终于弄清楚为什么我的代码在我使用的 php 中不起作用 如果(isset($_POST['delete'])) 但是当使用 javascript submit() 函数时,这个名称属性被删除。所以我像这样使用隐藏输入的名称 if(isset($_POST['topic_id_value'])) 并且它正常工作。

还是感谢给我提意见的小伙伴们