checkboxes
| From: | blackwater dev | Date: | Wed, 30 Nov 2005 03:15:36 +0000 |
| Subject: | checkboxes | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-226612@lists.php.net to get a copy of this message | ||
I have a form where I am dynamically building a bunch of checkbox
inputs. Then when submitted, I need to update the db. Problem is, of
course, if the checkbox is unchecked then the $_POST doesn't have the
value in the array. How can I get the value from $_POST even though
it's unchecked?
For example, here would be the generated form:
<input type="checkbox" name="cars[2]" value="1">Car 1
<input type="checkbox" name="cars[3]" value="1">Car 2
<input type="checkbox" name="cars[4]" value="1">Car 3
<input type="checkbox" name="cars[5]" value="1">Car 4
Then in the update I loop through:
foreach($_POST[cars] as $id=>$value){
//update vehicles set value to yes or no
}
But, if the unchecked values aren't in $_POST, how do I know to update them???
Thanks!