souloyster Posted January 3, 2007 Share Posted January 3, 2007 Hi,I've created a form with checkboxes in PHP and everything is sending fine except the word "array" appears at the beginning of the value display. How can I get rid of this?For example, the values for one checkbox group show up as:ArrayWash WallsWash WindowsClean BathroomsClean KitchenMake BedsPolish SilverWash ClothesWash LinensWash Dishes and PansHand Wash ClothesIron ShirtsIron LinensDustVacuum Link to comment https://forums.phpfreaks.com/topic/32739-form-checkboxes-and-arrays-newb/ Share on other sites More sharing options...
Psycho Posted January 3, 2007 Share Posted January 3, 2007 Need to see the code please. Link to comment https://forums.phpfreaks.com/topic/32739-form-checkboxes-and-arrays-newb/#findComment-152403 Share on other sites More sharing options...
souloyster Posted January 3, 2007 Author Share Posted January 3, 2007 Ok, the code for the checkboxes in the form is:... <tr> <td colspan="2" class="main"><input name="hkduties[]" type="checkbox" value="Wash Walls">Wash Walls </td> <td class="main"><input name="hkduties[]" type="checkbox" value="Wash Windows">Wash Windows </td> <td class="main"><input name="hkduties[]" type="checkbox" value="Clean Bathrooms">Clean Bathrooms </td> </tr> <tr> <td colspan="2" class="main"><input name="hkduties[]" type="checkbox" value="Clean Kitchen">Clean Kitchen </td> <td class="main"><input name="hkduties[]" type="checkbox" value="Make Beds">Make Beds </td> <td class="main"><input name="hkduties[]" type="checkbox" value="Polish Silver">Polish Silver </td> </tr> <tr> <td colspan="2" class="main"><input name="hkduties[]" type="checkbox" value="Wash Clothes">Wash Clothes </td> <td class="main"><input name="hkduties[]" type="checkbox" value="Wash Linens">Wash Linens </td> <td class="main"><input name="hkduties[]" type="checkbox" value="Wash Dishes and Pans">Wash Dishes & Pans </td> </tr> <tr> <td colspan="2" class="main"><input name="hkduties[]" type="checkbox" value="Hand Wash Clothes">Hand Wash Clothes </td> <td class="main"><input name="hkduties[]" type="checkbox" value="Iron Shirts">Iron Shirts </td> <td class="main"><input name="hkduties[]" type="checkbox" value="Iron Linens">Iron Linens </td> </tr> <tr> <td colspan="2" class="main"><input name="hkduties[]" type="checkbox" value="Dust">Dust </td> <td class="main"><input name="hkduties[]" type="checkbox" value="Vacuum">Vacuum </td> <td class="main"> </td> </tr>...The code for sending the data is: foreach($_POST['hkduties'] as $hkdutiesvalues) { $hkduties .= "$hkdutiesvalues\n"; } $body = "HOUSEKEEPING: $hkduties"; Link to comment https://forums.phpfreaks.com/topic/32739-form-checkboxes-and-arrays-newb/#findComment-152417 Share on other sites More sharing options...
.josh Posted January 3, 2007 Share Posted January 3, 2007 that's because hkduties[] makes an array. Each one would be accessed like so:$_POST['hkduties'][0]$_POST['hkduties'][1]$_POST['hkduties'][2]... Link to comment https://forums.phpfreaks.com/topic/32739-form-checkboxes-and-arrays-newb/#findComment-152423 Share on other sites More sharing options...
Psycho Posted January 3, 2007 Share Posted January 3, 2007 So, change your receiving page code to this:[code]<?php$body = "HOUSEKEEPING: ";if (!isset($_POST['hkduties'])) { $body .= "None";} else { foreach($_POST['hkduties'] as $hkdutiesvalues) { $body .= $hkdutiesvalues . "\n"; } }?>[/code] Link to comment https://forums.phpfreaks.com/topic/32739-form-checkboxes-and-arrays-newb/#findComment-152477 Share on other sites More sharing options...
souloyster Posted January 4, 2007 Author Share Posted January 4, 2007 Thanks for the help guys, but still the same problem. Something I probably should have mentioned is that the Housekeeping Duties get emailed with the other data in a plain text email. It still gets displayed as:HOUSEKEEPING: ArrayWash WallsWash WindowsClean BathroomsClean KitchenMake BedsPolish SilverWash ClothesWash LinensWash Dishes and PansHand Wash ClothesIron ShirtsIron Linens Link to comment https://forums.phpfreaks.com/topic/32739-form-checkboxes-and-arrays-newb/#findComment-152915 Share on other sites More sharing options...
Psycho Posted January 4, 2007 Share Posted January 4, 2007 Hmm... perhaps "array" is inthe aray as an actual value. Try doing this for debugging purposes:echo "<pre>";print_r($_POST['hkduties']);echo "</pre>";And post back the results here. Link to comment https://forums.phpfreaks.com/topic/32739-form-checkboxes-and-arrays-newb/#findComment-152960 Share on other sites More sharing options...
souloyster Posted January 4, 2007 Author Share Posted January 4, 2007 Here's the results:Array ( [0] => Wash Walls [1] => Wash Windows [2] => Clean Bathrooms [3] => Clean Kitchen [4] => Make Beds [5] => Polish Silver [6] => Wash Clothes [7] => Wash Linens [8] => Wash Dishes and Pans [9] => Hand Wash Clothes [10] => Iron Shirts [11] => Iron Linens ) Link to comment https://forums.phpfreaks.com/topic/32739-form-checkboxes-and-arrays-newb/#findComment-153003 Share on other sites More sharing options...
Psycho Posted January 4, 2007 Share Posted January 4, 2007 Oops, forgot to put the code within tags and some was consumed by the forum. No matter you got the results I was looking for. I see no reason why you would be getting the text "array" in your output. Could you post the code you are currently working with that builds that copy. Link to comment https://forums.phpfreaks.com/topic/32739-form-checkboxes-and-arrays-newb/#findComment-153165 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.