[PHP] Two word array Value
I am trying to use array's to populate a group of check boxes for a form. I am getting the checkboxes to print OK, but when the form is posted I am only getting part of the array. Form Page: $vars = array(Main Classroom = Main Classroom, Break Out Classroom = Break Out Classroom, Gym = Gym, Firearms Range = Firearms Range, EVOC Track = EVOC Track); $cols = 4; echo form method=post action=twocoltests.phptabletrtd colspan=.$cols. align=centerEquipment Needed/tdtr; foreach($vars as $key = $value){ if (($cols % 4) == 0 ){ echo /trtr; } echo tdinput name=.$key. type=checkbox value=.$value./tdtd.$value./td; $cols++; } echo /tr/table; echo br /; When I submit the form I am only getting the following having checked the boxes for Mail Classroom and Break Out Classroom. If I eliminate the spaces between the words, I get everything, but when I put the spaces between the words in the array, it cuts off the second word. Not sure what is happening? Array ( [Main] = Main [Break] = Break [Submit] = Submit )
Re: [PHP] Two word array Value
Try: echo tdinput name=.urlencode($key). type=checkbox value=.urlencode($value)./tdtd. $value./td; On Wed, May 14, 2008 at 4:02 PM, Mark Bomgardner [EMAIL PROTECTED] wrote: I am trying to use array's to populate a group of check boxes for a form. I am getting the checkboxes to print OK, but when the form is posted I am only getting part of the array. Form Page: $vars = array(Main Classroom = Main Classroom, Break Out Classroom = Break Out Classroom, Gym = Gym, Firearms Range = Firearms Range, EVOC Track = EVOC Track); $cols = 4; echo form method=post action=twocoltests.phptabletrtd colspan=.$cols. align=centerEquipment Needed/tdtr; foreach($vars as $key = $value){ if (($cols % 4) == 0 ){ echo /trtr; } echo tdinput name=.$key. type=checkbox value=.$value./tdtd.$value./td; $cols++; } echo /tr/table; echo br /; When I submit the form I am only getting the following having checked the boxes for Mail Classroom and Break Out Classroom. If I eliminate the spaces between the words, I get everything, but when I put the spaces between the words in the array, it cuts off the second word. Not sure what is happening? Array ( [Main] = Main [Break] = Break [Submit] = Submit )
Re: [PHP] Two word array Value
On Wed, May 14, 2008 at 4:02 PM, Mark Bomgardner [EMAIL PROTECTED] wrote: I am trying to use array's to populate a group of check boxes for a form. I am getting the checkboxes to print OK, but when the form is posted I am only getting part of the array. [snip!] Looks like someone's working with the police academy, or something similar. Reminds me I think I have to recert my CEVO and EVOC Anyway, using spaces in HTML form name and ID compartments is illegal, and you're not encapsulating the data in quotes. So HTML thinks that the first word of the bunch is the name of the form element, then skips the rest. For valid HTML: ?php // foreach echo tdinput name=\.str_replace(' ','_',$key).\ type=\checkbox\ value=\.$value.\/tdtd.$value./td; ? Otherwise, if you still want to use spaced form field names, you can enclose them in quotes (as shown above) and the browser will probably automatically urlencode() the data on submit. -- /Daniel P. Brown Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just $59.99/mo. with no contract! Dedicated servers, VPS, and hosting from $2.50/mo. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php