Re: Quick_Form - setting default value for a radio group

From: Date: Wed, 17 Sep 2003 05:26:04 +0000
Subject: Re: Quick_Form - setting default value for a radio group
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-7855@lists.php.net to get a copy of this message
Bertrand - Thanks for the excellent example. Cheers Graham At 11:15 PM 9/16/2003 +0200, Bertrand Mansion wrote:
<grahamc@53tech.com> wrote : Hi - I have a series of radio button groups crated as follows and I'm not able to have the default values be checked. foreach ( $r['response_set'] as $r_i ) {
       $scaled_items[] = & $form->createElement('radio',
'item_'.$r['item_id']. '[response_no]', NULL, NULL, $r_i['response_no']); } $form->addGroup($scaled_items, 'scaled_items'.$key, $r['item_id'] . ' - ' . $r['item_text'], NULL, false); This creates a series of scaled survey questions in a form. For example:
"Did the student demonstrate creative problem solving?"     [ ] Not at
all [ ] A little bit [ ] Kind of [ ] Most of the time [ ] Always. Each [ ] is a radio button with the only difference between the 5 being the value ( values are integers 1-5 ). So far I've tried adding the attributes array like this
       $scaled_items[] = & $form->createElement('radio',
'item_'.$r['item_id']. '[response_no]', NULL, NULL, $r_i['response_no'], array('checked'=>'checked')); I've also tried using $form->setDefaults($my_defaults); and changing the $appendName parameter to true. Hi, I'd do it like that: $labels = array('Not at all',
                'A little bit',
                'Kind of',
                'Most of the time',
                'Always');
$questions = array('Did you feed the cat ?',
                   'Did you vote for W. Bush ?');
foreach ($questions as $index => $question) {
    $radio = array();
    foreach ($labels as $value => $label) {
        $radio[] =& HTML_QuickForm::createElement('radio', null, null,
                    $label, $value);
    }
    $form->addGroup($radio, 'question_'.$index, $question, '<br />');
    $defaults['question_'.$index] = 0;
} $form->setDefaults($defaults); Bertrand Mansion Mamasam -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Graham Clarke GrahamC@53Tech.com www.53Tech.com 603.643.9955

« previous php.pear.general (#7855) next »