Details
Description
In Zend Framework before 1.5 the Zend_View Helper FormCheckbox had the feature, that a hidden field with the value "0" was always set befor the checkbox. This was a very helpful feature because if you have a lot of checkboxes each with a boolean value which has to be to be stored in the database (e.g a char(1) DEFAULT '0'::bpchar in a postgres DB or SET '0','1' in a mysql DB) you want to have the value 0 if the checkbox is not checked. In the normal behaviour the checkbox value is not submitted if it is not checked.
It's really simple to make this improvement in FormCheckbox.php:
FormCheckbox.php
public function Checkbox($name, $value = null, $attribs = null) { $info = $this->_getInfo($name, $value, $attribs); extract($info); // name, id, value, attribs, options, listsep, disable // is the element checked? $checked = ''; if (isset($attribs['checked']) && $attribs['checked']) { $checked = ' checked="checked"'; unset($attribs['checked']); } elseif (isset($attribs['checked'])) { unset($attribs['checked']); } // is the element disabled? $disabled = ''; if ($disable) { $disabled = ' disabled="disabled"'; } // XHTML or HTML end tag? $endTag = ' />'; if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) { $endTag= '>'; } // build the element // ADDED: here we built the hidden field $xhtml .= '<input type="hidden"' . ' name="' . $this->view->escape($name) . '"' . ' value="0"' . $endTag; $xhtml .= '<input type="checkbox"' . ' name="' . $this->view->escape($name) . '"' . ' id="' . $this->view->escape($id) . '"' . ' value="' . $this->view->escape($value) . '"' . $checked . $disabled . $this->_htmlAttribs($attribs) . $endTag; return $xhtml; }
It would be cool to have that again in this Helper.
Andy
Please evaluate and categorize/assign as necessary.