If the checkbox is checked, then the value of checkbox will be passed on the submission of the form. Otherwise, the value is empty. You can validate the value of a checkbox only after the form is being submitted.

For example:

<input type='checkbox' name='accept' value='1' id='checkbox' /> I accept the Terms & Conditions.

Use the following to check/validate the checkbox value at the server end

if (isset($_POST['accept'])) {
    echo "checked!";
}

Or 
if (!empty($_POST['accept'])) {
    echo "checked!";
}

Or 
if(isset($_POST['accept’]) && $_POST[‘accept’]!="")
{
    echo "checked!";
}

 

Last modified: March 13, 2019

Comments

Write a Reply or Comment

Your email address will not be published.