I’m trying to keep a list of checkboxes checked until post is valid and no errors. Below is the code I’m using. I would be thankful for any help.
<?php foreach ($drinks_checkbox as $option => $options){ ?>
<input type='checkbox' id='drinks[]' name='drinks[]' value='<?php echo $option;?>' <?php if(!empty($_POST['drinks'])){if($_POST['drinks']==$option){ echo "checked='checked'" ; }}?> /><?php echo $options;?><br />
<?php } ?>
I can successfully display the checked checkboxes using implode however I need help for the above..
$_POST[‘drinks’] is an array. Also, the id value does not need to be ‘drinks[]’
Try something like this:
Amended the !empty($drinksPost[$drinksIndex]) part and changed to associative.
If this doesn’t work, can you include $drinks_checkbox