Suppose we have a check box array demo[]
<input type="checkbox" name="demo[]" value="1" />A
<input type="checkbox" name="demo[]" value="2" />B
<input type="checkbox" name="demo[]" value="3" />C
To check if any checkbox is checked
if(!isset($_POST['demo'])){
echo "You need to check the checkboxs";
}
echo "You need to check the checkboxs";
}
To access the checkbox values using:
$_POST['demo'][0], $_POST['demo'][1], $_POST['demo'][2]
A
B
C
To make a default checked, for example in the second checkbox
<input type="checkbox" name="demo[]" value="2" checked />
Result for demo:
No comments:
Post a Comment