| disdat 2005-09-24, 6:57 pm |
| Hello, I am using HTML_Quickform_controller to create a wizard with 5
pages. On one page I need to pass an array to display repeating
elements on the next. I have not been able to get Smarty to resolve a
recursive element name. I have looked up recursion threads on Smarty
and checked out QF examples but haven't figured out how to fix things.
Any help will be greatly appreciated! Thanks.
Here is the code snippet from this page.
Context - The page is supposed to pull a list of performance measures
and IDs from the db and allow the user to enter a baseline number and
target against each measure that can then be saved. The number of
performance measures is dynamic and depends on user selections on
prior page(s).
+++
Bottomline - I want this HTML
<table>
=09</tr>
=09=09<td>J1</td>
=09=09<td>Jobs retained</td>
=09=09<td><input type=3D"text" name=3D"measureBaseline1"></td>
=09=09<td><input type=3D"text" name=3D"measureTarget1></td>
=09</tr>
=09<tr>=09
=09=09<td>J1</td>
=09=09<td>Jobs retained</td>
=09=09<td><input type=3D"text" name=3D"measureBaseline2"></td>
=09=09<td><input type=3D"text" name=3D"measureTarget2></td>
=09</tr>=09
</table>
+++++
//Here is the Smarty template. Something is screwed up in the way the
variables are being resolved. I get Array.measureTitle0.label etc. in
the output! I have tried several combinations of backticks and double
quotes but no luck.
{* form5.tpl *}
<table>
=09<tr>
=09=09<th>Measure Name</th>
=09=09<th>Type</th>
=09=09<th>Baseline</th>
=09=09<th>Target</th>
=09</tr>
=09{section name=3Di loop=3D$form_data.count.label}
{* form_data is assigned in HTML_QuickForm_Action_Display *}
=09<tr>
=09=09<td>{"$form_data.measureName`$smarty.section.i.index`.label"}</td>
=09=09<td>{"$form_data.measureTitle`$smarty.section.i.index`.label"}</td>
=09=09<td>{"$form_data.measureBaseline`$smarty.section.i.index`.html"}</td>
=09=09<td>{"$form_data.measureTarget`$smarty.section.i.index`.html"}</td>
=09</tr>
=09{/section}
</table>
//Here is the code behind the page
class Page_Step5 extends HTML_QuickForm_Page
{
function buildForm()
{
$this->_formBuilt =3D true;
$this->template =3D 'form5.tpl';
$getMeasures =3D "Select measure_id, measure_title from measures;
$measures =3D& $db->getAssoc($getMeasures);
$count=3D0;
foreach ($measures as $measureID =3D> $measureTitle) {=09=09
=09=09=09++$count;
=09=09=09$IDs[$count] =09=09=3D "measureID" . $count;
=09=09=09$measureTitles[$count] =3D "measureTitle" . $count;
=09=09=09$baselines[$count] =09=3D "measureBaseline" . $count;
=09=09=09$targets[$count] =09=09=3D "measureTarget" . $count;
=09=09=09
=09=09=09$this->addElement('static', $measureTitles[$count], $measure_title=
);
=09=09=09$this->addElement('text', $baselines[$count], 'Baseline:');
=09=09=09$this->addElement('text', $targets[$count], 'Target:');
=09=09}=09=09=09
$prevnext[] =3D& $this->createElement('submit',
$this->getButtonName('back'), '< Back');
$prevnext[] =3D& $this->createElement('submit', =20
$this->getButtonName('next'), 'Next >');
$this->addGroup($prevnext, 'buttons', '', ' ', false);
$this->setDefaultAction('next');
}
|