Hello, The checkbox element needs to execute some logic before rendering. This logic is inside the render() method of the element, so they are bypassed if you use the magic render*() methods. One solution is to duplicate that logic in your controller. See my reply in http://www.nabble.com/Zend_Form_Element_Checkbox-not-populating-state--to22378451.htmlfor an example. Another solution is to set the proper decorators and render the element whole.
-- Mon On Mon, Mar 23, 2009 at 1:42 PM, Jacky Chen <[email protected]> wrote: > sorry, > the controller of TestController should changed as this: > > TestController.php > > <?php > class TestController extends Zend_Controller_Action > { > > public function indexAction() > { > $form = new Zend_Form(); > > $checkElement = new Zend_Form_Element_Checkbox('checkElement'); > $checkElement->setUncheckedValue(0); > $checkElement->setCheckedValue(1); > $checkElement->setValue(1); > $checkElement->setRequired(1); > > $form->addElement($checkElement); > > if ($this->_request->isPost() && > $form->isValid($this->_request->getPost()) { > print_r($form->getValues()); > } > > $this->view->form = $form; > } > } > > > 2009/3/23 Jacky Chen <[email protected]> > > Hi there, >> there is a bug with the Zend_Form_Element_Checkbox, when i added a >> Checkbox element, with the checkValue 1 and unCheckedValue 0, to the form, >> and then render it with this >> banner,$this->form->checkElement->renderViewHelper(), then post the form >> with the checkElement unchecked to the same page that with the form , and >> then view the page source, the checkedValue and unCheckedValue of >> checkElement would be the same, with value 0. >> >> sorry for my poor english.do anyone understand me? or just try following: >> >> TestController.php >> >> <?php >> class TestController extends Zend_Controller_Action >> { >> >> public function indexAction() >> { >> $form = new Zend_Form(); >> >> $checkElement = new Zend_Form_Element_Checkbox('checkElement'); >> $checkElement->setUncheckedValue(0); >> $checkElement->setCheckedValue(1); >> $checkElement->setValue(1); >> >> $form->addElement($checkElement); >> >> $this->view->form = $form; >> } >> } >> >> views/scripts/test/index.phtml >> >> <html> >> <head> >> <title>template for the test controller index action</title> >> </head> >> <body> >> <form method="post"> >> >> checkElement:<?php echo $this->form->checkElement->renderViewHelper(); ?> >> <input type="submit" value="post the form" /> >> >> <p>leave the checkElement unchecked,then post this form,then search the >> value for the <input type="checkbox" name="checkElement" /> in the the page >> source,and see what?</p> >> >> </form> >> </body> >> </html> >> >> Best Regards, >> Jacky >> > >
