Error Message: Notice: Undefined variable: membership in line 100
Code:
if (isset($_POST['membership'])) {
$membership = implode(', ', $_POST['membership']);
} else {
$error['membership'] = 'Please select all that apply';
}
100) $message .= "Annual Membership/President\\'s Circle: $membership\\r\
\\r\
";
<fieldset>
<label for="membership">Please select all that apply:</label>
<input name="membership[]" type="checkbox" id="annualmembership" value="Annual Membership" <?php
$OK = isset($_POST['membership']) ? true : false;
if ($OK && isset($error) && in_array('Annual Membership', $_POST['membership'])) { ?> checked="CHECKED" <?php } ?> />
<label for="annualmembership">Annual Membership</label>
<input type="checkbox" name="membership[]" value="President's Circle" id="presidentcircle" <?php
if ($OK && isset($error) && in_array('President\\'s Circle', $_POST['membership'])) { ?> <?php } ?> />
<label for="presidentcircle">President's Circle (optional)</label>
<br />
<?php if (isset($error['membership'])) { ?>
<span class="warning"><?php echo $error['membership']; ?></span>
<?php } ?>
</fieldset>
OK. My first problem is that when my application first loads, the first checkbox selection is not checked–I thought I had that figured out.
My second problem is that if someone dechecks the selections (which shouldn’t happen), the correct error is applied, but then I get the “Notice: Undefined variable: membership in line 100” obviously caused by a checkbox option is not set.
How do I set the default checkbox? and how do I prefent the ‘Undefined’ error if someone decides to decheck the selections?