2008年8月31日星期日

[fw-mvc] Zend_Form_Element_Checkbox render a additional hidden input

<?php

 

include 'zend/view.php';

include 'zend/form/element/checkbox.php';

 

$view = new Zend_View();

$public = new Zend_Form_Element_Checkbox('public');

$public ->render($view);

echo $public;

 

?>

 

 

Will generate a hidden input :

 

<dt>&nbsp;</dt>

<dd>

<input type="hidden" name="public" value="0"><input type="checkbox" name="public" id="public" value="1"></dd>

 

My zf version is 1.6.0RC3, and I check the formCheckbox helper , I found the code like this :

 

// build the element

        $xhtml = '';

        if (!strstr($name, '[]')) {

            $xhtml = $this->_hidden($name, $checkedOptions['unCheckedValue']);

        }

                   $xhtml .= '<input type="checkbox"'

                . ' name="' . $this->view->escape($name) . '"'

                . ' id="' . $this->view->escape($id) . '"'

                . ' value="' . $this->view->escape($checkedOptions['checkedValue']) . '"'

                . $checkedOptions['checkedString']

                . $disabled

                . $this->_htmlAttribs($attribs)

                . $endTag;

 

But why should we add a hidden input ?

 

没有评论: