Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 400
Alex Pliutau Avatar asked Mar 12 '26 13:03

Alex Pliutau


1 Answers

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"); 
 }
like image 124
Jake N Avatar answered Mar 14 '26 03:03

Jake N



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!