views:

798

answers:

2

I have a radio element with two options. I want to set one as the default value in case the user forgets to check it. How can I do this?

Solution:

$this->addElement('radio', 'choose', array(
    'required'   => true,
    'multiOptions' => array(
        'yes' => 'heck yes',
        'no' => 'please no'
    ),
    'value' => 'yes' //key of multiOption
));
+1  A: 

use setValue with key. For example:

$enablestate=new Zend_Form_Element_Radio('enablestate');
$enablestate->addMultiOptions(array('enabled'=>'Enabled','unenabled'=>'Unenabled'));
$enablestate->setSeparator('')->setValue('enabled');
timpone
+1  A: 

this code should do it

$radio = new Zend_Form_Element_Radio('radio');
$radio->addMultiOption("option1", "option1")->setAttrib("checked", "checked");
$radio->addMultiOption("option2", "option2");
$this->addElement($radio);

for further readings you can refer to:

ZendFramework manual

http://www.w3schools.com/html/html_forms.asp

Mark Basmayor