ZF-3149: Improvement for Zend_View ->

Issue Type: Improvement Created: 2008-04-18T17:01:03.000+0000 Last Updated: 2009-05-12T10:12:09.000+0000 Status: Resolved Fix version(s): - 1.5.2 (15/May/08)

Reporter: Andreas Wenk (andy.wenk) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_View

Related issues: Attachments:


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:

<pre class="highlight">

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"';
        } elseif (isset($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 .= '_htmlAttribs($attribs)
               . $endTag;
        return $xhtml;

It would be cool to have that again in this Helper.



Posted by Wil Sinclair (wil) on 2008-04-18T17:13:04.000+0000

Please evaluate and categorize/assign as necessary.

Posted by Matthew Weier O'Phinney (matthew) on 2008-04-22T10:55:43.000+0000

Scheduling for next mini release; this has affected many legacy apps.

Posted by Matthew Weier O'Phinney (matthew) on 2008-04-25T16:15:25.000+0000

Resolved in trunk and 1.5 release branch by r9324

Posted by Ian Lewis (electricowl) on 2009-05-12T09:08:21.000+0000

I really take issue with this. It is poor design and breaks the model for those of us building forms with checkboxes.

If I wanted a hidden element then I should be able to extend the form checkbox to add it in, it's not rocket science. Unfortunately it does take some serious surgery to get rid of a hidden checkbox inserted without my even knowing about it.

It is a bad idea because: when working with the DOM in JavaScript a hidden element with the same name creates an array of elements. One of the effects of this is that a simple - if (oForm.my_checkbox.checked) will return undefined instead of true or false. changing it to if (oForm.my_checkbox[1].checked) should be my decision not one imposed on me.

The correct behaviour should be that an unchecked (unticked) checkbox should return no value on submit. It should be an option and not require a workaround.

Posted by Andreas Wenk (andy.wenk) on 2009-05-12T10:12:01.000+0000

"If I wanted a hidden element then I should be able to extend the form checkbox to add it in, it's not rocket science."

Having the possibility to set a parameter in the attribs would be the best way to handle it. I fully agree.

In most cases it is good to get a value also from a checkbox. Submitting a form with a input field results always in recieving the field - if it's empty or not. So why not having this behaviour with all form fields? To have full conformity with the HTML specs you are right if you expect the behaviour you described ('cause that's the way it is in HTML). The intention to have the hiodden field in this helper was because I always find it annoying when a checkbopx does not submit a value.



Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.