Alex Pliutau
Alex Pliutau

Reputation: 21957

Zend Form Checkbox checked

How can I make checkbox checked in Zend Framework depending on the variable value? For example, I have $some_value = 'yes'; - checkbox should be checked, unchecked otherwise. Thanks.

Upvotes: 2

Views: 24673

Answers (1)

Jake N
Jake N

Reputation: 10583

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"); 
 }

Upvotes: 11

Related Questions