flashpointdevon Posted October 3, 2011 Share Posted October 3, 2011 Im using chrome. Shouldt these have a 1 value only if checked? I tried without assigning value and with, I cant get it to work right. Same for radio boxes. I tried googling this and to my surprise I could not find anything relevant. How do I get a 0 for not checked and a 1 for checked? Thanks in advance im sure someone knows this <input type="checkbox" name="test_clean" id="test_clean" value="1" /> <label for="test_clean">Test Clean</label> <input type="checkbox" name="test_works" id="test_works" value="1" /> <label for="test_works">Test Works</label> <input type="checkbox" name="test_parts" id="test_parts" value="1" /> <label for="test_parts">Test Parts</label> <input type="checkbox" name="test_volume" id="test_volume" value="1" /> <label for="test_volume">Test Volume</label> <input type="checkbox" name="test_damage" id="test_damage" value="1" /> <label for="test_damage">Test Damage</label> <input type="checkbox" name="shipped" id="shipped" value="1" /> <label for="shipped">Shipped</label> Quote Link to comment https://forums.phpfreaks.com/topic/248363-checkboxes-and-radio-boxes-not-working-right-i-think/ Share on other sites More sharing options...
requinix Posted October 3, 2011 Share Posted October 3, 2011 How do I get a 0 for not checked and a 1 for checked? By starting with a 0 for every possible checkbox and then setting each to 1 if they've been submitted. That's because unchecked boxes are not sent to PHP. $checkboxes = array( "test_clean" => 0, "test_works" => 0, "test_parts" => 0, "test_volume" => 0, "test_damage" => 0, "shipped" => 0 ); foreach ($checkboxes as $key => &$value) { if (!empty($_POST[$key])) $value = $_POST[$key]; } unset($value); Quote Link to comment https://forums.phpfreaks.com/topic/248363-checkboxes-and-radio-boxes-not-working-right-i-think/#findComment-1275421 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.