我有一个$_POST
指向同一页面的删除输入按钮。我有一个 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
而不发布表单后自行关闭。当我注释掉这段代码时,按钮工作正常,并删除记录(帖子成功)。