Forum Moderators: coopster
<form action="" method="post">
<input type="checkbox" name="check_list[]" alt="Checkbox" value="one">
<input type="checkbox" name="check_list[]" alt="Checkbox" value="two">
<input type="checkbox" name="check_list[]" alt="Checkbox" value="three">
<button type="submit">submit</button>
</form>
<?php
echo "Check box test<pre>" ;
print_r($check_list);
echo "</pre>";
if(!empty($_POST['check_list'])) {
foreach($_POST['check_list'] as $check) {
echo "check=$check<br>";
}
}
?>
Check box test
Array
(
[0] => one
[1] => two
[2] => three
)
check=one
check=two
check=three
//create array to temporarily grab variables
$input_arr = array();
//grabs the $_POST variables and adds slashes
foreach ($_POST as $key => $input_arr) {
$_POST[$key] = addslashes($input_arr);
}
addslashes — Quote string with slashes
foreach ($_POST as $key => $value) {
if (is_array($value)) {
// reset the temporary array
$input_arr = array();
foreach ($value as $array_val) {
// Build the temporary array of values
array_push($input_arr,addslashes($array_val));
}
// After array is stepped through, NOW replace this key with the array
$_POST[$key] = $input_arr;
}
else { $_POST[$key] = addslashes($value); }
}