Jump to content

Form checkboxes and arrays (newb)


souloyster

Recommended Posts

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 Walls
Wash Windows
Clean Bathrooms
Clean Kitchen
Make Beds
Polish Silver
Wash Clothes
Wash Linens
Wash Dishes and Pans
Hand Wash Clothes
Iron Shirts
Iron Linens
Dust
Vacuum
Link to comment
https://forums.phpfreaks.com/topic/32739-form-checkboxes-and-arrays-newb/
Share on other sites

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 &amp; 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">&nbsp;</td>
    </tr>
...

The code for sending the data is:

foreach($_POST['hkduties'] as $hkdutiesvalues)  {
$hkduties .= "$hkdutiesvalues\n";
}

        $body = "HOUSEKEEPING: $hkduties";
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]
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 Walls
Wash Windows
Clean Bathrooms
Clean Kitchen
Make Beds
Polish Silver
Wash Clothes
Wash Linens
Wash Dishes and Pans
Hand Wash Clothes
Iron Shirts
Iron Linens
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 )
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.