0

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">

enter image description here

Here is $personal_data array img

5
  • Cross check that $personal_data must have key & value with same name of your checkbox Commented May 24, 2013 at 6:23
  • it have the same name as checkbox but value 1 Commented May 24, 2013 at 6:27
  • Than it should work.Can you post the name ? I assume it must have FORM_CHECKBOX_PREFIX too in that. Commented May 24, 2013 at 6:32
  • it just a prefix to chk "chk_is_conveyance_required"... yeah it should work but Commented May 24, 2013 at 6:41
  • @Rikesh question has been updated Commented May 24, 2013 at 6:43

1 Answer 1

2

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);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.