Submitting disabled checkbox?
I am toying around with a settings form for a CMS interface and ran into this quandary.
There are settings which are dependent on settings in other forms in the CMS controls , and as such may OR MAY NOT not be altered in the current form. My first instinct is to have my PHP script add DISABLED to the input in the case I want to prevent the user from changing its state ( that is if the input is checked it remains checked if it's not then it cannot be checked)
The problem stems from the fact that DISABLING an input prevents its value from being sent when the form is submitted AND that an unchecked checkbox does not send its value either. In other words there is actually no way of differentiating a CHECKED DISABLED checkbox from merely an UNCHECKED checkbox. ( is there? I mean there is no READONLY equivalent for checkboxes?)
So far what I was doing was to have the PHP script output a hidden input with a the same name and value as the disabled checkbox. This might have seemed as a an OK workaround, but it makes me nervous when I add AJAX to my form. That is if the information on the form is changed so that the checkbox has to be enabled... (via .js).. I also have to remove the hidden input... OK.. minor inconvenience... but if it's changed again and the checkbox acquires a different value and goes back to being disabled.. I need to append the form with a new hidden input.
My fear is that all this writing and unwriting screws something up, DOM wise or otherwise somewhere down the stream. It seems like a read only state for a checkbox would be such an obvious part of that input type's behaviour, one that would solve this issue so gracefully that I have wondered if I have missed something here.
As always, your input ( pun) is appreciated.