...

View Full Version : PHP with check boxes



alex86
05-06-2009, 09:20 PM
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

devinemke
05-06-2009, 09:40 PM
a simple example:


<?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';}
}
?>

alex86
05-07-2009, 09:39 AM
Thank you for the code.

That's a great help to get me started.

thecsslab
05-07-2009, 03:32 PM
I just want to notice that you can also use array-style names of the input fields such as user[preferences] and user[password].



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum