RE: [PHP] Array of CheckBoxes
| From: | César Aracena | Date: | Wed, 26 Jun 2002 03:26:44 +0000 |
| Subject: | RE: [PHP] Array of CheckBoxes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-103902@lists.php.net to get a copy of this message | ||
Dumb me!!! Now I see why you said that one should be checked at least!!!
Guess I over-saw the looping part down there!!!
Thanks a lot...
> -----Original Message-----
> From: John Holmes [mailto:holmes072000@charter.net]
> Sent: Wednesday, June 26, 2002 12:23 AM
> To: 'César Aracena'; 'PHP General List'
> Subject: RE: [PHP] Array of CheckBoxes
>
> Well, if you have this:
>
> <input type='checkbox' name='name[]' value='one'>
> <input type='checkbox' name='name[]' value='two'>
>
> Then on your processing page, you'll have $HTTP_POST_VARS['name'][]
> array. If one was checked, then you'll have $HTTP_POST_VARS['name'][0]
> == 'one'. To see how many boxes were checked, you can do
> count($HTTP_POST_VARS['name']);
>
> Hope that helps...
>
> ---John Holmes...
>
> > -----Original Message-----
> > From: César Aracena [mailto:icaam@icaam.com.ar]
> > Sent: Tuesday, June 25, 2002 11:16 PM
> > To: holmes072000@charter.net; 'PHP General List'
> > Subject: RE: [PHP] Array of CheckBoxes
> >
> > 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 dont 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
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php