I've been looking through common.inc, and am puzzled by the fact that the form_checkbox code makes a call to form_hidden, which as far as I can tell leads to any checkbox tag being preceded by a hidden tag that defines the same variable. I can't come up with a reason for this behavior---I would assume that it is illegal or at least ill defined to have an html page where the same input variable is defined twice. And I am also suspicous of the fact that this form_hidden call is not invoked on any form creation function call other than form_checkbox.

Comments

killes@www.drop.org’s picture

A comment in the code has been added:

// Note: because unchecked boxes are not included in the POST data, we include
// a form_hidden() which will be overwritten for a checked box.

--
If you have troubles with a particular contrib project, please consider to file a support request. Thanks.

chx’s picture

There are several sites with multiple instances of var[]. PHP will handle this as an array. But you may also use <input name=var> as many times you wish, just use $_SERVER['RAW_POST_DATA'] under PHP, which is not populated always per default.

As for the checkboxes -- these two tags <input name=edit[chk1] type=hidden value=0> <input name=edit[chk1] type=checkbox value=1> lets you check whether the value of $edit['chk1'] is 0 or 1. If you omit the hidden field, you'd need isset to check. Only the checkbox field needs an isset, but now not even that. That's why there is only a hidden call from checkbox. So this is a very nice hack, actually.

The HTML fathers most probably was envious of SQL folks who were unable to make a unified INSERT-UPDATE (and a very similar SELECT) syntax, so they made a total disaster with the totally different syntax of all INPUT elements. Have you tried to write a good validate script in JS...?

--
Drupal development: making the world better, one patch at a time. | A bedroom without a teddy is like a face without a smile.