Re: checkboxes

From: Date: Wed, 30 Nov 2005 05:17:19 +0000
Subject: Re: checkboxes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-226618@lists.php.net to get a copy of this message
Well if your keys are a straight sequence of numbers instead of a foreach you can do a for loop and for those whose value is not one, set to zero. Matt "blackwater dev" <blackwaterdev@gmail.com> wrote in message news:34a9824e0511291915q4854cffew3a01bf306c1d5fba@mail.gmail.com... 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!

« previous php.general (#226618) next »