How to get a regular Checkbox in a Zend Form

checkboxzend-formzend-framework

I have a form in Zend_Form that needs some checkboxes and I'd like them to be regular old checkboxes. You know, you give em a name and a value. If they are checked your post data contains name=>value.

Zend_Form is generating two inputs fields. One, the checkbox with a value=1 and the second a hidden input with a value=2. Both have the same name. I understand in theory how Zend expects the checkbox to work, but that's not how I expect it to work and it's not how I want it to work. How do I get my old fashion HTML checkbox back?

I have tried using $this->createElement, $this->addElement and creating a Zend_Form_Element_Checkbox manually. None allow me to set the checkbox's value and all generate the hidden input.

Best Answer

The final and REALLY correct answer is to add an option to the element :

$this->addElement('checkbox', 'my_element', array(
    'label' => 'My Element Label',
    'name' => 'my_element_name',
    'disableHidden' => true
));