tags:

views:

36

answers:

1

I have a checkbox. My script generate this checkbox and assign value of checkbox as 'yes'/'no'. How can I do with Zend next thing. If value is 'yes' checkbox is checked, and inside out.

+2  A: 

Hi

Thought I would have a go at this, your question is badly written, but I will do my best. There are are a few solutions below, I have not tested them all. Give them a try.

Example 1

 // create your checkbox
 $checkbox_element = new Zend_Form_Element_Checkbox("mycheckbox");     


 // Set the value to 1 if needed
 if($some_value == "yes")
 {
      $checkbox_element->setValue(1);
 }

Example 2

 // Check if value is set
 if($some_value == "yes")
 {
      // Create checkbox element and Set the attribute 'checked' to 'checked' 
      $checkbox_element = new Zend_Form_Element_Checkbox("mycheckbox", array("checked" => "checked"); 
 }   
 else
 {
      // Othrewise create the checkbox which is not checked
      $checkbox_element = new Zend_Form_Element_Checkbox("mycheckbox"); 
 }
jakenoble