Reputation: 8012
IN this way checkbox is created
$is_conveyance_required = new Zend_Form_Element_Checkbox(FORM_CHECKBOX_PREFIX . 'is_conveyance_required', array());
$is_conveyance_required->addDecorators(array(
array('HtmlTag', array('tag' => 'label')),
array('Label', array('tag' => '')),
));
$is_conveyance_required->setValue(1);
$is_conveyance_required->setChecked( true );
$this->addElement($is_conveyance_required);
and how form populating
$personal_form->populate($personal_data);
But zend form not populating checkbox...
<input type="checkbox" value="1" id="chk_is_conveyance_required" name="chk_is_conveyance_required">
Here is $personal_data array img
Upvotes: 0
Views: 6794
Reputation: 1200
It's simply not working how you expect it to operate.
From the Zend Manual:
By default, the checked value is '1', and the unchecked value '0'. You can specify the values to use using the setCheckedValue() and setUncheckedValue() accessors, respectively. Additionally, setting the value sets the checked property of the checkbox. You can query this using isChecked() or simply accessing the property. Using the setChecked($flag) method will both set the state of the flag as well as set the appropriate checked or unchecked value in the element. Please use this method when setting the checked state of a checkbox element to ensure the value is set properly.
You could do some workaround by using something like this (untested!) in you controller as addition to popuplate()
if($personal_form->is_conveyance_required->getValue() == 1) {
$personal_form->is_conveyance_required->setChecked(true);
}
Upvotes: 2