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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP with check boxes

    Hi there everybody,

    I'm sure that this has been asked before, but I've looked through and can't find an answer and I'm running out of time.

    I have a site that I'm building for uni and have some check boxes. When the check boxes are checked, I need the username of the user to be posted onto another page. Is this possible? I have no idea how to do it, since I don't understand php at all.

    Also, on another page, where these names are posted there are check boxes with those names. I need it so that when the user checks the boxes and clicks submit, the names of the checked ones show on another page.

    Any help at all would be very grateful, like I say, I'm running out of time and the whole thing is stressing me out.

    Thank you in advance

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    a simple example:
    PHP Code:
    <?php
    function form()
    {
        echo 
    '<form action="" method="post">';
        
        for (
    $i 1$i <= 5$i++)
        {
            echo 
    '<input type="checkbox" name="users[]" value="' $i '"'; if (isset($_POST['users']) && in_array($i$_POST['users'])) {echo ' checked';} echo '> user ' $i '<br>';
        }
        
        echo 
    '
        <input type="submit" name="submit" value="submit">
        </form>
        '
    ;
    }

    if (!isset(
    $_POST['submit']))
    {
        
    form();
    }
    else
    {
        
    form();
        
        if (isset(
    $_POST['users'])) {echo 'you checked the following users: ' implode(', '$_POST['users']);}
        else {echo 
    'you did not check any users';}
    }
    ?>

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for the code.

    That's a great help to get me started.

  • #4
    New to the CF scene
    Join Date
    May 2009
    Location
    Bulgaria
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I just want to notice that you can also use array-style names of the input fields such as user[preferences] and user[password].


  •  

    Posting Permissions

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