【问题标题】:Zend Form Checkbox checkedZend 表单复选框已选中
【发布时间】:2010-08-24 16:17:17
【问题描述】:

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

【问题讨论】:

  • 从里到外?你在问什么?
  • @Iznogood,我猜是inside out,他的意思是vice versa
  • @shamittomar 没错,他的问题并没有告诉我们太多。但是,嘿,如果您理解他,请随时回答。我认为他应该发布一些代码和更好的解释。

标签: php zend-framework checkbox zend-form


【解决方案1】:

我想我会尝试一下,你的问题写得不好,但我会尽力而为。下面有几个解决方案,我没有全部测试过。试试看。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多