Ryukotsusei Posted June 21, 2010 Share Posted June 21, 2010 I have a form with a set of checkboxes that I would like to verify with PHP. I want the PHP to display one message for the ones that are checked, and a different message if they're not. However, the code seems to be labeling them all as checked for some reason. It can't seem to identify when they're not. Checkbox in the form: <input type='checkbox' name='codes[]' value='$code'> My loop: $codes=$_POST['codes']; for($i=0;$i<count($codes);$i++) { if(isset($codes[$i])) { $status="$code was selected."; } else { $status="$code was not selected."; } } I've been looking everywhere for an answer, but I can't seem to figure out where I'm going wrong. Help please? Also, I thought it would be helpful to note that if I leave them all unselected, no message at all is shown (I don't currently have a default for $status). But even if I only check one, all of them receive the "was selected" message. Quote Link to comment Share on other sites More sharing options...
gizmola Posted June 21, 2010 Share Posted June 21, 2010 The way html works, is that checkboxes exist in the POST data when they are checked. When they are not checked they don't exist. Quote Link to comment 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.