Making checkboxes sticky

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lettie
Forum Newbie
Posts: 15
Joined: Fri Jan 28, 2005 6:57 am

Making checkboxes sticky

Post by lettie »

Hi chaps

I'm creating an intelligent form for my site. It basically generates form fields based on what was selected from the previous field so as to only show relevant questions. The form is sticky so it remembers inputs using the if(isset($_POST['var'])) to populate values when the form is submitted to itself.

I have a section which allows users to select multiple checkboxes to create an array. What I need to do is make this sticky so when the continue button is pressed the values ticked remain ticked. I've tried the code below but when submitted it checks all the boxes even if only one/some are checked initially.

Any help appreciated.

Cheers
echo '<input name="products[]" type="checkbox" value="books"';
if(isset($_POST['products']) AND $_POST['products'][]='books')
{
echo ' checked';
}
echo '>';
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

if(isset($_POST&#1111;'products']) && in_array('books', $_POST&#1111;'products']))
lettie
Forum Newbie
Posts: 15
Joined: Fri Jan 28, 2005 6:57 am

Fantastic

Post by lettie »

Cheers feyd works a treat. Many Thanks!
Post Reply