How get value for unchecked checkbox in checkbox elements when form posted?

前端 未结 11 2444
独厮守ぢ
独厮守ぢ 2020-11-27 17:13

I have a form like below :

11条回答
  •  醉话见心
    2020-11-27 17:25

    Assuming we are using checkboxes with zeros or ones...

    Using a hidden checkbox with a zero value is just a work-around. Another work around would be to add 0 to the value when receiving the post or get.

    Example:

    $chkbx1 = $_POST['chckbx1']; $chkbx1 += 0;

    This takes a NULL value an turns it into a zero, but if the value is one, as in its checked, then the value stays the same.

    The real issue here isn't inventing a work-around. Its understanding why this is happening. Older versions of mySQL takes null values and converts them into a zero. In newer versions, you must disable strict mode and then a work-around is not needed.

提交回复
热议问题