Checked checkbox?

I would add a hidden input field with the same name before the checkbox:

<input type="hidden" name="email_opt_in" value="0" />

Because the forms are processed sequentially you would get “0” if the form was submitted, but the checkbox wasn’t checked (instead of not getting anything).

Then assume the checkbox is checked if the form wasn’t submitted or if it was submitted and the checkbox was checked:

$checked = !isset($_POST['email_opt_in'])
             || (isset($_POST['email_opt_in']) && $_POST['email_opt_in']);

Later:

... <?php checked($checked); ?>

The entire idea is to store the unchecked state of the checkbox in case of an input error, so the user doesn’t have to check it again if he didn’t want to on the first submission.

Sorry for this long and boring answer for this simple question 🙂

techhipbettruvabetnorabahisbahis forumutaraftarium24edueduedueduedueduedusedueduedus