选中Zend表格复选框

时间:2010-08-24 16:17:18

标签: php zend-framework checkbox zend-form

如何根据变量值在Zend Framework中选中复选框? 例如,我有$some_value = 'yes'; - 复选框应检查,否则取消选中。感谢。

1 个答案:

答案 0 :(得分:11)

以为我会对此有所了解,你的问题写得不好,但我会尽我所能。下面有几个解决方案,我还没有测试过。试一试。

示例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);
 }

示例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"); 
 }
相关问题