-1


This looks like a possible duplicate but there are a lot questions on how to check if a checkbox is checked and I couldnt find any about checking if a checkbox even exists. So please be so kind and answer this silly question

I tried: if (isset($_POST['box']))
returns false if the box exists but is not checked

if (is_null($_POST['box']))

error (Undefined offset: 1) if the box exists and is not checked

Are there other functions to try ? Any advice for a workaround ?

Any help will be appreciated. Thanks.

indrox
  • 39
  • 6

1 Answers1

0

Browsers only submit checkboxes that are checked. So if $_POST['box'] exists (isset($_POST['box']) === true), the checkbox was checked. And if it does not exist, the checkbox was not checked.

Arjan
  • 9,784
  • 1
  • 31
  • 41