Page 1 of 1

Making checkboxes sticky

Posted: Fri Jan 28, 2005 7:12 am
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 '>';

Posted: Fri Jan 28, 2005 8:02 am
by feyd

Code: Select all

if(isset($_POST&#1111;'products']) && in_array('books', $_POST&#1111;'products']))

Fantastic

Posted: Fri Jan 28, 2005 8:13 am
by lettie
Cheers feyd works a treat. Many Thanks!