I'm using the following code for a series of check-boxes.
How can I change the code to prevent the checkboxes from emptying when user submits the form.
<?php
$services = array(
'Tree Felling',
'Height Reduction',
'Crown Thinning',
'Deadwooding/Ivy Removal',
'Stump Grinding',
'Other'
);
foreach ($services as $option) {
?>
<label><input id="<?= $option ?>" type="checkbox" name="services[]" <?php
if ($_POST['services'] == $option) {
echo 'CHECKED';
}
?> value="<?= $option ?>" /><?= $option ?></label>
<?
}
?>
I tried this - but It didn't work out. Am I on the right lines?
<?php
$services = array(
'Tree Felling',
'Height Reduction',
'Crown Thinning',
'Deadwooding/Ivy Removal',
'Stump Grinding',
'Other'
);
foreach ($services as $option) {
?>
<label><input id="<?= $option ?>" type="checkbox" name="services[]" value="<?= $option ?>" /><?= $option ?></label>
<?
}
?>