Re: HTML_QuickForm2: value of unchecked checkbox
| From: | Alexey Borzov | Date: | Sat, 12 Jun 2010 20:34:53 +0000 |
| Subject: | Re: HTML_QuickForm2: value of unchecked checkbox | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-53558@lists.php.net to get a copy of this message | ||
Hi Christian,
On 02.06.2010 0:38, Christian Weiske wrote:
HTML forms always had the problem that checkboxes get not submitted when they are not checked. This leads to E_NOTICEs in the best or program errors in the worst case if this cases are not checked properly. I think QF2 should make programming with forms easy, and that means that the value of a checkbox should be either boolean true or false - no matter what the HTML form specifics say.In fact checkbox value was forced to '1' in HTML_QuickForm and we received several requests to change this behaviour: http://pear.php.net/bugs/bug.php?id=4564 http://pear.php.net/bugs/bug.php?id=17485 You can get a boolean like this: (bool)$box->getAttribute('checked');
This could be solved in two ways: 1) adding a hidden field before the checkbox, with the same name and value of "0" 2) programmatically fix the value when using getValue().We have an 'advcheckbox' element in HTML_QuickForm which implements your option 1), it won't be difficult to port that to HTML_QuickForm2.