Zend Form Checkbox checked
How can I make checkbox checked in Zend Framework depending on the variable va开发者_开发技巧lue?
For example, I have $some_value = 'yes';
- checkbox should be checked, unchecked otherwise. Thanks.
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");
}
精彩评论