Please note that the data submitted will be within the scope of <form>....</form>
由於您有兩個(gè)表單,當(dāng)您點(diǎn)擊第一個(gè)表單中的提交按鈕時(shí),它不會(huì)將第二個(gè)表單的資料傳送到伺服器。
因此,請(qǐng)將第二種形式變更為:
<form action="delete-register.php" method="post"> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" id="<?php echo $row['id']; ?>" name="selected[]" value="<?php echo $row['id']; ?>"> <label class="custom-control-label" for="<?php echo $row['id']; ?>"></label> </div> <input type=submit name=delete> </form>
[補(bǔ)充說明]
#如果您想堅(jiān)持使用第一種形式來觸發(fā)刪除操作,那麼請(qǐng):
id=form2
in the 2nd form so as to facilitate triggering of the submission by form1這是修改後的程式碼:
<form method="post"> <button type="button" class="btn btn-primary"><span class="fe fe-file-plus fe-12 mr-2"></span>New</button> <button type="button" name="delete" class="btn btn-secondary" onclick='document.getElementById("form2").submit()'; ><span class="fe fe-trash fe-12 mr-2"></span>Delete</button> </form> <form id=form2 action="delete-register.php" method="post"> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" id="<?php echo $row['id']; ?>" name="selected[]" value="<?php echo $row['id']; ?>"> <label class="custom-control-label" for="<?php echo $row['id']; ?>"></label> </div> <input type=hidden name=delete value="delete"> </form>