I have a web form that has a check box in it. The form is created dynamically so there could be multiple checkboxes on this form. I need to know whether it is checked or not. The problem is an unchecked checkbox POSTs nothing at all.
I know this has been asked before but the solution is always to provide a hidden field with a the value. The problem I have is I need to know whether it was checked out not, not necessarily the value. Is there a way to make this happen? I was thinking I would need to use some javascript but not really sure how to go about it.
You could create a hidden input with the same name but the value
"off". Make sure it is located before the checkbox in the document. Example:This will submit the following:
Since duplicate names results in overwriting the previous value (except in the case of arrays), you will always get
$_POST['something']that is either"on"(checked) or"off"(unchecked).