Using Flexy::Elements for radio buttons in foreach loops

From: Date: Sun, 24 Oct 2004 19:24:22 +0000
Subject: Using Flexy::Elements for radio buttons in foreach loops
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-15079@lists.php.net to get a copy of this message
Hi I'm trying to use HTML_Template_Flexy_Element when creating an online quiz and I've hit a problem with loops generating radio buttons - if the tags name attribute is dynamic, the radio buttons are not checked. Here's some code fragments to show what I mean: while ($qList->fetch()) {
      $buttonName = 'frmAnswer['.intval($qList->quiz_id).']';
      $elements[$buttonName] = new HTML_Template_Flexy_Element;
      if (!empty($output->answers[$qList->quiz_id])) {
         $output->flexyElements[$buttonName]->setValue($output->answers[$qList-
quiz_id]); }
      :
} On this template: {foreach:results,key,valueObj} : <ol type="A"> <li><label><input type="radio" value="1" type="radio" value="2" name="frmAnswer[{valueObj.quiz_id}]"
            id="frmAnswer_{valueObj.quiz_id}b"
            />{valueObj.answer2:h}</label></li>
<li><label><input type="radio" value="3" name="frmAnswer[{valueObj.quiz_id}]"
            id="frmAnswer_{valueObj.quiz_id}c"
            />{valueObj.answer3:h}</label></li>
: </ol> </div> {end:} - The selected buttons don't get marked as checked. They do if the element names are fixed ie: <li><label><input type="radio" value="3" name="frmAnswer[0]"
            id="frmAnswer_0c" />{valueObj.answer3:h}</label></li>
Is there a workaround? I've googled and searched but not found any examples of this issue - if there is, point me in the right direction and I'll take it from there. Thanks Peter

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