Set default radio button with Zend_Form_Element_Radio

Setting a default value (‘CHECKED’) in Zend_Form_Element_Radio is done with the function setValue(). This is an example of how to to this in Zend Framework 1.10

...
$typeOfLap = new Zend_Form_Element_Radio('typeoflap');
$typeOfLap->setRequired(true)
          ->addFilter('StripTags')
          ->addFilter('StringTrim')
          ->setDecorators(array('ViewHelper'))
          ->addMultiOptions(array(
               'Practice' => 'Practice',
               'Qualifying' => 'Qualifying'))
          ->setValue('Practice');
...

As most things in Zend this is also very simple.

Comments are closed.

Niklas Tech Blog
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.