Jump to content

how do i check if a checkbox is checked or not in php ?


jd2007

Recommended Posts

Example:

<?php

if(isset($_POST['submit']))
{
    if(isset($_POST['chk_box'][0]) && $_POST['chk_box'][0] == 'somevalue')
    {
        echo 'checkbox1 - Selected';
    }
    else
    {
        echo 'checkbox1 - Not Selected';
    }
}

?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  Checkbox1: <input type="checkbox" name="chk_box[]" value="somevalue" /><br />
  Checkbox2: <input type="checkbox" name="chk_box[]" value="anothervalue" /><br />
  <input type="submit" name="submit" value="Submit Checkboxes" />
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.