ZF-6596: Checkbox, I never get the check/unchecked value...always get the hidden field value
Description
I always get the value of the hidden field, never from the checkbox, when I submit my form. I am using the last Zend Framework version ( but also also was happening the same in previous versions), Firefox 3 and PHP 5
How to test this:
In /forms I created a new form:
class Form_NewSystem extends Zend_Form {
$decors = array(
array(array('Elem' => 'ViewHelper'), array('separator' => '')), // i reset the separators to get rid
array('Label', array('separator' => '')), // those unpredictable newlines
array('Errors', array('separator' => '')), // in the render output
);
$this->addElement('checkbox', 'active', array(
'label' => 'Active',
'value' => '1',
'decorators' => $decors
));
}
In the view:
<?= $this->form->active->renderLabel(); ?>
<?= $this->form->active->renderElem(); ?>
<?= $this->form->active->renderErrors(); ?>
In the controller:
$form = new Form_NewSystem();
if ($this->getRequest()->isPost()) {
print_r($request->getPost());
if ($form->isValid($request->getPost())) {
//do something here
}
}
//....populating the form here
$form->setAction($this->_helper->url('edit'));
$this->view->form = $form;
$this->render('name of the view here');
It doesn't matter if I check the checkbox or not, I always get the hidden value (by default 0). Also if I set different unCkecked value, the hidden field ignores it, and puts 0 instead!.
I really don't know what could be wrong..
Comments
Posted by old of Satoru Yoshida (yoshida@zend.co.jp) on 2009-05-22T21:42:04.000+0000
set component and auto reassign
Posted by Fabio Almeida (fabius) on 2009-11-05T13:48:40.000+0000
I'm having the same issue with Firefox 3.5. Apparently the UNNECESSARY hidden input inserted automatically by ZF is triggering this behaviour. The hidden input serves no other purpose than to return a "zero value" in $_POST. In the above example, it would return "$_POST['active']=0" instead of just sending "nothing".
I believe this shouldn't be done in the first place (two elements with the same name leads to unpredictable results), and now it's affecting Firefox's behaviour (not a firefox bug, IMO). It works in IE8, but God only knows if it will work in IE9, for example.
Posted by Ethan Gruber (ewg118) on 2010-03-22T11:46:36.000+0000
I am also facing the same problem. I tried resorting to using javascript to set the value of the checkbox to 1 or 0, but that does not work either. The value defined in the controller overrides whatever value I use javascript to set in the browser.
Posted by John Malone (pro777) on 2010-03-26T08:50:51.000+0000
I'm having the same issue with both Zend_Form_Element_CheckBox and Zend_Dojo_Element_CheckBox. Only seeing this issue in FF; Chrome and IE8 work just fine.
Posted by Andras Gyomrey (andras) on 2010-09-02T13:40:28.000+0000
I'm havng the same problem... At least if this won't be fixed, could somebody point out a clean 'decorator' solution?
Posted by Frank Brückner (frosch) on 2012-07-27T12:05:56.000+0000
I can not reproduce the problem. (Firefox 14.0.1 and ZF 1.11.11)
I see no problem with Framework.