Zend framework Checkbox issue
Hi The problem with Zend_Form_Element_Checkbox is that when it renders it is creating a hidden input field with the same name as the actual checkbox. So let's see the code:
This is how i create the element inside form:
$onlineCheckbox = $this->createElement('checkbox', 'online_checkbox', array(
'label'=>'Online:',
'uncheckedValue'=> '0',
'checkedValue' => '1'
));
And this is the Output html look like:
<input type="hidden" name="online_checkbox" value="0" /><input type开发者_C百科="checkbox" name="online_checkbox" id="online_checkbox" value="1" />
Now the problem is that in Other browsers then Firefox i get the needed results via post( if unchecked '0', if checked '1') but in Firefox for both cases i get '0', i know that this is because of that hidden field. I googled and seems that this issue is not figured out. So my question is how do others manage this , or may be there is a solution to make this work in firefox. Any help will be appreciated. Thank in advance.
EDIT: Thank to @Marcin - i think the problem is in my decorators. In Firebug i get a messy output, i think that if i will arrange them correctly it will work, again thank @Marcin for pointing out!
You probably have a Dojo enabled form. The Zend_Dojo_View_Helper_CheckBox renders a hidden element and the form element. You can specify the plain old check box like so:
$onlineCheckbox = new Zend_Form_Element_CheckBox('online_checkbox', array(
'label'=>'Online:',
'uncheckedValue'=> '0', //can be removed, this is the default functionality
'checkedValue' => '1', //can be removed, this is the default functionality
));
This will by pass Zend_Form::createElement()'s plugin loader.
Happy Hacking!
You need to use a IdenticalValidator as workaround for this issue:
->addValidator('Identical', false, '1');
精彩评论