I have this code for a few check-boxes, works fine like this
foreach($_POST as $key => $order_type) {
if ('1' == $_POST[$key]) $_POST[$key] = '0';
}
if I negate the if it stops working and I’m sure that some are not == ‘1’; it just sets them to NULL.
foreach($_POST as $key => $order_type) {
if ('1' != $_POST[$key]) $_POST[$key] = '0';
}
do I miss anything ? tried with !('1' == $_POST[$key]) too.
Thanks
Checkboxes only get sent to the server if they are checked.
I assume that they have a value of
1, so you will be able to find these in the$_POSTarray. However, there will be none where the value is0(unless you specify a value of0in the html and check the box…).To check checkboxes, you need to use
issetas the value is really not that important, it is either set (checked) or not and then it simply does not appear.