Checkbox in Form

3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 17, 2013   (RSS)

By Daryl - July 17, 2013

Hi depdesign,

Try adding a hidden field with the same field name:

<input name="accept" value="0" type="hidden">
<input name="accept" value="1" checked="checked" type="checkbox" <?php if(@$_REQUEST['accept']){echo "checked='checked'";}?>>

How this works is if the checkbox is unchecked and submitted, the $_REQUEST['accept'] will still have a value of 0 coming from the value of the hidden field. 
And if the checkbox is checked, it will overwrite that value to the value of the checkbox which is 1. Just make sure that the hidden field is on top of the checkbox.

Cheers,

Daryl

Daryl Maximo
PHP Programmer - interactivetools.com

By depdesign - July 17, 2013

Thanks Daryl, your solution worked perfectly!

Dan Perez