Forum Moderators: coopster
I know this should be simple, but I'm having trouble with it. Any help would be appreciated.
// importance is the name of the checkboxes
<?php
for ($x = 0; $x < count($importance); $x++)
echo "<p>$importance[$x]</p>"; // prints checked values
?>
if it's been checked, you'll get
$_POST['check']=1
but if it's not checked, it won't appear in the post array, so
if(!isset($_POST['check']))
echo "The checkbox isn't checked";
but if it's not checked, it won't appear in the post array, so
if(!isset($_POST['check']))
echo "The checkbox isn't checked";
Thanks for your response, but I tried that. Problem is, the "Checkbox isn't checked" appears on the page when the page loads, BEFORE the form is submitted. I want it to appear after the form is submitted, if and only if there were not checkboxes selected.
if(isset($_POST['Submit'])) {
if(!isset($_POST['check'])) {
echo "The checkbox isn't checked";
} // EndIf no checkboxes checked
} // EndIf the form has been submitted
Hidden checkbox field in the html:
<input type="hidden" name="checkbox[]" value="0" />
And the php:
elseif ($type == "0") { // hidden checkbox value
echo "No checkboxes were checked";
}
Since the $_POST array for the checkboxes only gets populated with values of boxes that are checked, PHP uses the only value provided, which is "0".