我需要帮助防止选中和未选中的复选框同时发布


I need assistance preventing both a checked and unchecked checkbox from posting at the same time

我创建了一个复选框表。行按类别划分,选中或未选中的复选框将显示在部门列下。我有很多代码,所以我会分解我提供的内容。我正在通过每列创建一个数组(奇数方法,是的)。我注意到,如果取消选中所有复选框,则每次循环时都会返回隐藏值0。太好了,这正是我想要的。但是,如果选中该框,它将同时返回值0和值3。例如:

测试=阵列()

测试[0]=>0测试[1]=>3

如何防止它发布隐藏值?

$row_two = mysql_query("SELECT dept_id FROM categories WHERE cat_name = '{$cats['cat_name']}' and bus_id = '{$busUnits['bus_id']}'");
            while (($test_two=mysql_fetch_assoc($row_two)))
            {
                $AnotherTest =  implode(',', $test_two);
                $WhatTest = explode(",", $AnotherTest);
                if(in_array("3",$WhatTest, TRUE))
                {
                    echo '<input type="hidden" name="Cat_CBC_Test_One[]" value="0">';
                    echo '<td><input type="checkbox" name="Cat_CBC_Test_One[]" value="3" checked></td>';
                }
                else
                {
                    echo '<input type="hidden" name="Cat_CBC_Test_One[]" value="0">';
                    echo '<td><input type="checkbox" name="Cat_CBC_Test_One[]" value="3"></td>';
                }

要检测未选中的复选框,我会添加一个具有不同名称的隐藏字段,如_Cat_CBC_Test_One。这样你就不会有隐藏场干扰的问题。

然后,在服务器上,扫描以_开头的参数,并添加缺少的"false"参数以进行进一步处理。