代码之家  ›  专栏  ›  技术社区  ›  Alex Pliutau

选中Zend窗体复选框

  •  2
  • Alex Pliutau  · 技术社区  · 14 年前

    如何根据变量值在Zend框架中选中复选框? 例如,我有 $some_value = 'yes';

    1 回复  |  直到 12 年前
        1
  •  11
  •   Jake N    14 年前

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

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