我有一個刪除輸入按鈕,$_POST
s到同一頁。我有一個jQuery確認模式,點擊時彈出。如果是,那麼它發佈表單,如果沒有,則取消該操作。jquery模式確認問題
<?php
if ($_POST['doDelete'] == 'Delete') {
if (!empty($_POST['u'])) {
foreach ($_POST['u'] as $uid) {
$id = filter($uid);
if (deleteRecord('projects', $id, false)) {
$fail[] = $id;
} else {
$pass[] = $id;
}
}
}
$msg = new Messages();
if (!empty($pass)) {
$passed = implode(', ', $pass);
$message = "Deleted: {$passed}";
$msg->add('s', $message);
}
if(!empty($fail)){
$failure = implode(', ', $fail);
$message = "Could not delete/an error occured: {$failure}";
$msg->add('e', $message);
}
redirect('projects.php');
}
?>
<script>
$(function() {
$("#dialog-confirm-multiple").dialog({
autoOpen: false,
resizable: false,
width: 300,
modal: true,
show: {
effect: "bounce",
duration: 100
},
hide: "drop",
buttons: {
"Yes": function() {
$("#confirm").submit();
},
"No": function() {
$(this).dialog("close");
}
}
});
$("#doDelete").click(function (e) {
e.preventDefault();
$("#dialog-confirm-multiple").dialog('open');
return false;
});
});
</script>
<form post="self.php" id="confirm">
<!-- some inputs .etc -->
<input name="doDelete" type="submit" id="doDelete" value="Delete" class="btn btn-danger">
</form>
按鈕ID是doDelete
,並且形式id爲confirm
。然而,該模式僅在用戶單擊yes
而未發佈表單後纔會自行關閉。當我註釋掉這段代碼時,按鈕工作正常,並刪除記錄(帖子成功)。
到類似:jquery dialog: confirm the click on a submit button
什麼警告?刪除哪些帖子? – mishik
請添加您的html的相關部分。你在哪裏以及如何設置'currentForm'? –
我說得更清楚了。 'currentForm'被註釋掉了。如果用戶點擊是,我只想提交確認。因此'$(「#confirm」)。submit();' – Alex