我使用下面的代碼在我的php文件中獲取多個複選框的值。在POST變量中也包含未選中的框 - 多個複選框
if(!empty($_POST['check_list'])) {
foreach($_POST['check_list'] as $check) {
update_comment_meta($check, 'consider', 1);
}
}
問題是,這段代碼顯然只在數組$_POST['check_list']
中加入了檢查值。
我的需求是通過將'0'作爲第三個參數而不是'1'來執行函數update_comment_meta
。
有關詳細信息,我給的代碼生成HTML表單:
<form action="" id="primaryPostForm" method="POST">
<?php
$defaults = array(
'post_id' => $current_post);
$com= get_comments($defaults);
foreach ($com as $co) {
if(get_comment_meta($co->comment_ID, 'consider', true)==1) {
?><input type="checkbox" name="check_list[]" value="<?php echo $co->comment_ID; ?>" checked="checked">
<?php }
else {
?><input type="checkbox" name="check_list[]" value="<?php echo $co->comment_ID; ?>" >
<?php
}}
</form>
你平常的幫助總是讚賞。
這就是它的工作原理。你知道沒有檢查哪些值沒有被髮送。 – PeeHaa
您可以使用AJAX(jQuery)發送數據,而您可以完全控制行爲。 – silkfire
@PeeHaa埽我用你的評論來找到解決方案,我在上面寫過。非常感謝你。 –