I have a form containing checkboxes. Once the form is submnitted I know that count($_POST[‘arrayname’]) return the numbers of checked checkboxes. Can PHP count the number of checkboxes in a form regardless of checked or not? Or do I need Javascript for that?
@NogDogFeb 25.2011 — #Unfortunately, the HTML specification has it that only checked checkboxes get sent in the form data, so PHP will not know about any unchecked ones. You could certainly do something with JavaScript, with the usual caveat that JavaScript may not be enabled by all users, plus a malicious user can easily bypass it. You could consider as an alternative to add a hidden field for each checkbox with a different name but the same naming convention (e.g. using the "[]" array naming convention) to get your total via that name. <i> </i><label><input type="checkbox" name="check[]" value="1" />Foo</label> <input type="hidden" name="all_check[]" value="0" /> <label><input type="checkbox" name="check[]" value="2" />Bar</label> <input type="hidden" name="all_check[]" value="0" />