Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the default checked value of a Zend_Form Radio Element?

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
));
like image 542
Andrew Avatar asked Feb 27 '23 22:02

Andrew


1 Answers

use setValue with key. For example:

$enablestate=new Zend_Form_Element_Radio('enablestate');
$enablestate->addMultiOptions(array('enabled'=>'Enabled','unenabled'=>'Unenabled'));
$enablestate->setSeparator('')->setValue('enabled');
like image 173
timpone Avatar answered Mar 23 '23 01:03

timpone