2008年8月31日星期日

Re: [fw-mvc] Zend_Form_Element_Checkbox render a additional hidden input

Thanks for your quick response !
This not the perfect way , because in the javascript coding, we usually use document.forms['formName'].elements['elementName'] to get the element object ,

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

In the code, we use document.forms['formName'].elements['public'] to get the public checkbox, but it will only return the hidden input .

-------------------------------
(on Sunday, 31 August 2008, 08:01 PM +0800):
> But why should we add a hidden input ?

To ensure a value is actually sent. When a checkbox is not checked, it
does not send a key for that element when the form is submitted. Adding
the hidden element ensures that the unchecked value is transmitted. This
is done to ensure that a value for the element is always present.

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: