Question

<form method="POST">

    <input type="checkbox" id="hrm" name="hrm" />

</form>

I mean when the form is posted.

Was it helpful?

Solution

$_GET['hrm'] or $_POST['hrm'] (depending on your form's method attribute) will be set to 'On' if it is checked, or will not be set at all if it's unchecked. In essence, you can just check using isset($_GET['hrm']) (or _POST if that's the case) - if isset() returns true, then it was checked.

OTHER TIPS

<input type="checkbox" id="hrm" name="hrm" value="yes" />


<?php

if ( isset( $_POST['hrm']) && $_POST['hrm'] === 'Yes' ) {
}

?>

This how:

<?PHP
if($_POST['hrm']=='ok') echo 'checked';
else echo 'not';
?>

or:

<?PHP
if(isset($_POST['hrm'])) echo 'checked';
else echo 'not';
?>

But first you have to give value for it:

<input type="checkbox" id="hrm" name="hrm" value='ok' />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top