I have a comment section handling name/phone/comment/etc. I have a checkbox in this form as well. I get the error exception to produce when the checkbox set is empty. But if boxes are checked, and other areas aren't satisfied, I can't get the boxes to stay checked while the errors are thrown elsewhere and the page is reloaded.
I tried setting the values and $response in the if statements to yes, but if one box is checked, when the page reloads all boxes are checked.
PHP:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["response"])) {
$responseErr = "Response is required";
} else {
$response = test_input($_POST["response"]);
}
}
How would you prefer us to respond? Choose all that apply.
<span class="error">*
<?php echo $responseErr;?>
</span>
<br>
<input type="checkbox" name="response" <?php if (isset($response) && $response=="Call") echo "checked";?> value="Call">Call
<input type="checkbox" name="response" <?php if (isset($response) && $response=="Text") echo "checked";?> value="Text">Text
<input type="checkbox" name="response" <?php if (isset($response) && $response=="Email") echo "checked";?> value="Email">E-mail
<br><br>