vendredi 20 janvier 2017

Setting checkbox to checked using PHP is results in no way to clear the checked attribute after render

I have a checkbox in my form which looks like this:

<input class="form-control" type="checkbox" value="1" id="showCTA" name="showCTA" <?php echo $block['showCTA'] ? 'checked' : ''; ?> />

Everything works fine with this mark up....unless the PHP value equals 1(already checked). If this is the case, I can check and uncheck the box in the from end visually, but the actual html attribute does not change resulting in the same value of 1 being saved to my database on submit.

How can I work around this in a clean manner? I assume the issue is since the PHP value is absolute until submitted, it means the condition around my "checked" attribute is also absolute, therefore I cannot change the attribute.




Aucun commentaire:

Enregistrer un commentaire