Re: Posted form values - checkbox problem

From: Date: Mon, 18 Dec 2000 22:44:13 +0000
Subject: Re: Posted form values - checkbox problem
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-30955@lists.php.net to get a copy of this message
Got around this one, but it was kinda ugly... The whole issue is that the checkboxes names are multidimensional arrays I'm passing around. Based on things people selected before, there could be dozens of different combinations of array keys. I was using cow as a simplistic example <input type="checkbox" name="v[5][4][3]"> <input type="checkbox" name="v[5][4][2]"> <input type="checkbox" name="v[5][4][1]"> <input type="checkbox" name="v[5][8][6]"> <input type="checkbox" name="v[5][8][7]"> <input type="checkbox" name="v[5][8][8]"> etc. is what I'm dealing with, but I can never be certain what those array keys will be. What I ended up doing (for anyone else who might face similar issues) is creating a 'ghost' array with the same keys, all values set to 0, so I can go through THAT array structure to see all the possible combinations, then deal with the inputted value. Hope that helps someone in the future, and thanks all for the feedback. Michael Kimsal wrote: > cow1.php > <form method="post" action="cow2.php"> > <input type="checkbox" name="cow"> > <input type="submit"> > </form> > > cow2.php > <? echo phpinfo();?> > > If you run cow1.php, then have it submit to cow2, > there will be no HTTP_POST_VARS["cow"] unless > the "cow" is checked. I've no way of knowing > if 'cow' was the name of a checkbox on the form that > wasn't checked, or just not a checkbox at all. > > Runing PHP4.03pl1 if that makes a difference. > > David Tod Sigafoos wrote: > > > Hello Michael, > > > > Monday, December 18, 2000, 13:51:27 PM, you wrote: > > > > MK> <input type="checkbox" name="cow"> > > MK> <input type="checkbox" name="pig"> > > MK> <input type="checkbox" name="dog"> > > > > MK> If cow is 'checked', I get $cow="on", > > MK> but if cow is left unchecked, I get $cow="". > > > > MK> If I knew the names of the variables I was > > MK> getting, I could check to see if they were 'on' or '', > > MK> but I don't know. I'm getting an array of disparate > > MK> values, and I can't tell which checkboxes were on > > MK> or off, only those that were on. > > > > MK> Any ideas, short of including a separate hidden value that > > MK> tells me which variable names I'll be getting? > > > > I am sure I am missing something .. but the control 'name' is the var > > name. You know you have a checkbox called cow, pig and dog so you > > will have vars $cow, $pig and $dog... yes? > > > > wait a minute .. am i on candid camera? <g> > > > > > > -- > ========================== > Michael Kimsal > http://www.tapinternet.com > PHP Training courses > http://www.tapinternet.com/php > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net -- ========================== Michael Kimsal http://www.tapinternet.com PHP Training courses http://www.tapinternet.com/php

« previous php.general (#30955) next »