Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder Andy92's Avatar
    Join Date
    Nov 2005
    Location
    Horsham, West Sussex, UK
    Posts
    363
    Thanks
    7
    Thanked 1 Time in 1 Post

    Php Form Processing

    Hi there,

    Ive done php form processing before, but there is something im stuck on.

    I have a form, and a php while loop, that connects to the database, and prints rows of data.

    PHP Code:
    <input type='checkbox' name='inboxcheck[";
        echo $foo++;
        echo "]' 
    value='$row2[id]' /> 
    So, it would print, say eg ...

    <input type='checkbox' name='inboxcheck[1]' value='7' />
    <input type='checkbox' name='inboxcheck[2]' value='11' />
    <input type='checkbox' name='inboxcheck[3]' value='17' />
    <input type='checkbox' name='inboxcheck[4]' value='20' />

    So then i select the textboxes, say i select inboxcheck[2] and inboxcheck[4]

    Then, it goes to the process.php page, and this is what i have...

    PHP Code:
    @extract($_POST);
    $inboxcheck stripslashes($inboxcheck);

    echo 
    $inboxcheck
    But, because i selected 2 and 4, instead of writing this...

    PHP Code:
    @extract($_POST);
    $inboxcheck[2] = stripslashes($inboxcheck[2]);
    $inboxcheck[4] = stripslashes($inboxcheck[4]);

    echo 
    $inboxcheck[2];
    echo 
    $inboxcheck[4]; 
    I dont know what checkboxes users are going to select, so is there any way of displaying the values of all the checkboxes they select like...

    PHP Code:
    @extract($_POST);
    $inboxcheck[numbers] = stripslashes($inboxcheck[numbers]);

    echo 
    $inboxcheck[numbers]; 
    So as i selected 2 and 4, it will echo 11 and 20.


  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    This will remove empty items, and apply stripslashes to every item.
    PHP Code:
    $inboxcheck array_map('stripslashes'array_filter($_POST['inboxcheck']));
    echo 
    implode(' '$inboxcheck); 
    The numbers will be separated by a space. You can check to see if the array is empty() before imploding it if you wish.

  • #3
    Regular Coder Andy92's Avatar
    Join Date
    Nov 2005
    Location
    Horsham, West Sussex, UK
    Posts
    363
    Thanks
    7
    Thanked 1 Time in 1 Post
    Thanks! It works!


  •  

    Posting Permissions

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