Привет! Analysis & Solutions wrote: > On Fri, Jul 12, 2002 at 10:59:00PM -0400, Blue Presley wrote: > >>Hello. I have a form that I would like to use checkboxes. >>... snip ... >>I've been told that if I want to manipulate each >>one then I should use 'name=checkbox[]' and make an array out of it. okay, >>fine. but how do i access them in my PHP script? I know I have to use the >>$_POST[] array, but this creates a multidiminsional array, yes? do i access >>it like $_POST[checkbox[1]]?? or $_POST[checkbox][1]?? > > > The latter. But note, if a box isn't checked, it's not going to be > sent, so won't be in the array. > > <form> > <input type="checkbox" name="StateID[]" value="32" /> NV > <input type="checkbox" name="StateID[]" value="33" checked /> NH > <input type="checkbox" name="StateID[]" value="34" checked /> NJ > </form> > > In this case $_POST['checkbox'][0] would be 33 and ...[1] would be 34. > > Sometimes it's handy to identify the key upfront: > > <form> > <input type="checkbox" name="StateID[32]" value="608" /> NV > <input type="checkbox" name="StateID[33]" value="2" /> NH > <input type="checkbox" name="StateID[34]" value="40" checked /> NJ > </form> > > That would yield $_POST['checkbox']['34'] = 40. > > A nice way to handle incomming checkboxes is this: > > while ( list($Key, $Val) = each($checkbox) ) { > # do what you need to do... > # for example, show what was sent... > echo "<br />$Key = $Val\n"; > }
Just one thing, as someone noted a week ago or so, you can't use the [] syntax *and* javascript. If you also need to process your checks from jscript side you shall resort to some older method and have your variables called like <input type="checkbox" name="StateID_32" value="608" /> NV <input type="checkbox" name="StateID_33" value="608" /> NV then process it with variable variable names (the $$ syntax). пока Альберто Киев @-_=}{=_-@-_=}{=_-@-_=}{=_-@-_=}{=_-@-_=}{=_-@-_=}{=_-@-_=}{=_-@ LoRd, CaN yOu HeAr Me, LiKe I'm HeArInG yOu? lOrD i'M sHiNiNg... YoU kNoW I AlMoSt LoSt My MiNd, BuT nOw I'm HoMe AnD fReE tHe TeSt, YeS iT iS ThE tEsT, yEs It Is tHe TeSt, YeS iT iS ThE tEsT, yEs It Is....... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php