Sunday, 18 August 2013

how to see if all checkboxes are empty in php

how to see if all checkboxes are empty in php

In PHP, how do I see if all checkboxes are empty? This is an excerpt from
my code: Basically, I want to use an "if" and "else" code that is
specifically for when all my checkboxes are unchecked.
$titlebox=isset($_GET['title']) ? "checked='checked'" : '';
$authorbox=isset($_GET['author']) ? "checked='checked'" : '';
// keeps checkboxes checked after submit
<form action="" method="get">
<input type="text" name="search">
<input type="submit" value="Search">
<input type="checkbox" name="title" '.$titlebox.' >
<label for="title">Title</label>
<input type="checkbox" name="author" '.$authorbox.' >
<label for="author">Author</label>
</form>
// form
if (isset($_GET['title']))
{ $searchbooktitle = $bookfieldtitle;
}
else
{ $searchbooktitle = NULL;
};
// this is how I get individual checkboxes.
The last part shows how I get individual checkboxes, but how do I get all
the checkboxes and see if they are empty? I'd like to use a specific "if"
and "else" code that will strictly apply only if all checkboxes are
unchecked.
The answer might be simple but I'm new at this and confused. Please help!

No comments:

Post a Comment