Forum Moderators: coopster
I seem to be having a problem with some code I have written to collect data from checkboxes in an HTML form, and pass them to database values. I will start by giving a short example of my form data:
<form action="form.php" method="post">
<input type="checkbox" name="ckbx[]" value="val1" />Value 1<br />
<input type="checkbox" name="ckbx[]" value="val2" />Value 2<br />
<input type="checkbox" name="ckbx[]" value="val3" />Value 3<br />
etc...
<input type="button" value="Submit" onclick="submitForm(); return false;" /> <--- The return false here is because I am submitting this form via AJAX
I have found that when I submit the form, the 'ckbx' array is being passed ALL of the checkbox values, not just the ones that are checked. For example, I have this code in my form.php file for debugging:
$checkboxes = $_POST['ckbx'];
$string = implode($checkboxes,",");
$msg = $string;
$msg2 = $_POST['ckbx'];
...
echo $msg;
print_r($msg2);
...and regardless of which are checked or unchecked I get this output:
val1, val2, val3 Array ( [0] => val1 [1] => val2 [2] => val3 )
Now, by doing heavy research on the POST values of checkboxes, no values should be sent for boxes that weren't checked. But for some reason, they are all set to 'on' every time, even if they are all unchecked. Any help would be greatly appreciated.
BTW, this is my first post. If I have posted this in the wrong area, please let me know. Thanks!