RE: [PHP] Array of CheckBoxes

From: Date: Wed, 26 Jun 2002 03:15:32 +0000
Subject: RE: [PHP] Array of CheckBoxes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-103898@lists.php.net to get a copy of this message
Ok. Now, I like the idea of creating the array from the "name[]" of the checkbox, but if I point it to phpinfo.php it won't show the name[] array passed trough $HTTP_POST_VARS, so I don't know see how the script will know if a checkbox even exist. How does PHP handle this? > -----Original Message----- > From: John Holmes [mailto:holmes072000@charter.net] > Sent: Tuesday, June 25, 2002 11:56 PM > To: 'César Aracena'; 'PHP General List' > Subject: RE: [PHP] Array of CheckBoxes > > Hmm..only problem with this is that if a checkbox is not checked, it's > variable isn't set at all. > > <input type='checkbox' name='one' value='1'> > <input type='checkbox' name='two' value='2'> > > If you check 'one', you have a variable $one == 1. If you leave 'two' > blank, then you get nothing. $two isn't set at all. > > So, the first part of your solution is easy, the array of values that > were checked... > > <input type='checkbox' name='name[]' value='one'> > <input type='checkbox' name='name[]' value='two'> > <input type='checkbox' name='name[]' value='three'> > > So when that is submitted, as long as one checkbox was checked, you'll > have a $name[] array that contains one, two, or three, based on which > ones were checked. > > What you could do, if you know how many checkboxes there were supposed > to be, is use something like this... > > <input type='checkbox' name='name[1]' value='one'> > <input type='checkbox' name='name[2]' value='two'> > <input type='checkbox' name='name[3]' value='three'> > > the process like this: > > <? > for($x=0;$x<$Num_Checkboxes;$x++) > { > if(!isset($name[$x])) > { $name[$x] = FALSE; } > } > ?> > > That'll check for missing keys in the $name array and assign a false > value to them... > > Anyway...I'm rambling... :) > > ---John Holmes... > > -----Original Message----- > > From: César Aracena [mailto:icaam@icaam.com.ar] > > Sent: Tuesday, June 25, 2002 10:38 PM > > To: PHP General List > > Subject: [PHP] Array of CheckBoxes > > > > Hi all. > > > > I have a form in which I must add a set of check boxes at the bottom. > > Once the form is passed away, the information of the checked boxes > > should be inserted into a DB. The thing is that I don’t like to use > > ‘tons’ of “if” statements ‘cause it will have way too many check > boxes… > > Is there any way of creating an Array which holds TRUE for check boxes > > that where selected and NULL for the ones leaved clear? The final > table > > with the data stored should look like this: > > > > > +---------+-----------------+-----------+-----------+-----------+------- > > -----+-----------+ > > | userid | date | option1 | option2 | option3 | option4 | > > option5 | > > > +---------+-----------------+-----------+-----------+-----------+------- > > -----+-----------+ > > | 1 | 2002-06-25 | true | true | false | false > > | true | > > | 2 | 2002-06-25 | false | true | true | false > > | false | > > | 2 | 2002-06-25 | true | false | false | true > > | true | > > > +---------+-----------------+-----------+-----------+-----------+------- > > -----+-----------+ > > > > Haw can this be achieved? If no can do, I will have to do if… else if… > > else if… else if… and way too far down the page… else. > > > > Thanks in advance, > > > > <mailto:webmaster@icaam.com.ar> Cesar Aracena > > CE / MCSE+I > > Neuquen, Argentina > > +54.299.6356688 > > +54.299.4466621 > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#103898) next »