Results 1 to 4 of 4

Thread: Form data!

  1. #1
    Join Date
    Sep 2007
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Form data!

    Hi,

    I have a list of posts generated from a mysql database with checkboxes whose name is their corresponding post's ID, and using those checkboxes one should be able to delete the posts.

    I've tried
    PHP Code:
    print_r($_POST['todelete']);
             
            foreach(
    $_POST['todelete'] as $key => $my_var) {
                
    printf("Key #%d has the value <strong>%s</strong>"$key$my_var);
            } 
    But that only shows the checks that are on, like:
    Key #0 has the value onKey #1 has the value onKey #2 has the value onKey #3 has the value on
    So, I'm basically asking how to retrieve the data from all form elements, checkboxes, regardless if they are on or off.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Can you show your form's html markup?

  3. #3
    Join Date
    Sep 2007
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    HTML Code:
    <input type='checkbox' name='todelete[]'>
    All entries are ordered, so I can match up which ones are being deleted.

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    okay:

    you will never get "off" checkboxes to show up. they're just not supposed to.

    two possible solutions:

    1) number your checkboxes. I think this is the quickest, most straightforward solution. this way, it's easy to see which item the checkbox belongs to.
    HTML Code:
    <input type="checkbox" name="todelete[1]">
    <input type="checkbox" name="todelete[2]">
    <!--etc.-->
    2) use radios instead. that way, you'll get a "yes" or "no" value for each item. However, you'll need two buttons for each item, and I <i>think</i> you might need to index them anyway; or your yes/no counts might get confused.
    HTML Code:
    <input type="radio" name="todelete[1]" value="yes"> Delete
    <input type="radio" name="todelete[1]" value="no"> Keep

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
  •