Results 1 to 6 of 6

Thread: using foreach for unchecked boxes

  1. #1
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default using foreach for unchecked boxes

    How can you use foreach() and $_POST to retrieve and display all of the information including values from checkboxes where the checkboxes were not checked?

    For example
    PHP Code:
    $a=0;
    foreach (
    $_POST as $field[] => $value[])
    {echo 
    "$field[$a] = $value[$a]<br>";$a++;} 
    will display all of the values except for the values from checkboxes that were not checked.

    any ideas?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You can't -- unchecked checkbox values are not sent by the browser.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Oct 2007
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    You could assume that all boxes are unchecked unless checked though.
    ?
    Last edited by magik; 02-26-2008 at 06:02 AM.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Yeah, certainly, if there is no value it's checked, but that won't let you know what the names of the fields were, which is why looping through them would help. So, not sure what to suggest here. Best just write out an array of the field names and remove those from the array that ARE checked, then you have a list of those that are not.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Thanks guys. One idea I came up with was to put all of the fields into an array and then loop through the array similar to what djr33 was suggesting. If that makes sense.

  6. #6
    Join Date
    Jan 2008
    Posts
    32
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Wouldn't it be easier instead of un-checking things you DON'T want, to check things that you do? Unless you're doing some type of signup form or something.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •