Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.2.16

Request #14995 Enhance Smarty Renderer to gen multi-dim array for 'hidden' HTML elements.
Submitted: 2008-11-11 22:34 UTC
From: ivanbarrios Assigned: avb
Status: Closed Package: HTML_QuickForm (version 3.2.10)
PHP Version: 5.2.6 OS: MacOS
Roadmaps: 3.2.11    
Subscription  


 [2008-11-11 22:34 UTC] ivanbarrios (Ivan Barrios)
Description: ------------ It would be helpful to have the ArraySmarty Renderer generate a multi- dimensional array for 'hidden' type HTML elements, as it does for other element types. (where a separate sub-array is generated using the 'name' attribute) This is helpful when one is generating multiple 'hidden' elements. (on separate rows of a table, for example) Test script: --------------- <?php require_once 'Smarty.class.php'; require_once 'HTML/QuickForm.php'; require_once 'HTML/QuickForm/Renderer/ArraySmarty.php'; $form = new HTML_QuickForm('interactive_form', null , null , null , array('class' => 'network_form')); for ($i=1; $i<10; $i++) { $form->addElement('hidden', 'network_id' . $i, $i); $form->addElement('radio', 'radio'.$i, null, null, 'Car'); $form->addElement('radio', 'radio'.$i, null, null, 'Truck'); } // end for $form->addElement('submit', 'Submitbtn', 'Update', array('id' => 'update_button')); // Create Renderer to generate Smarty-compatible data $renderer = & new HTML_Quickform_Renderer_ArraySmarty($smarty); // Generate Smarty-compatible HTML for form $form->accept($renderer); // DEBUG print_r($renderer->toArray()); // send form to Smarty template $smarty->assign('form', $renderer->toArray()); if ($form->validate()) { /* fill space */ } else { $smarty->display('example.tpl'); } // end if validate() ?> Expected result: ---------------- Script will generate a $form array containing: $form['hidden'] = <input name="network_id1" type="hidden" value="1" /> <input name="network_id2" type="hidden" value="2" /> <input name="network_id3" type="hidden" value="3" /> <input name="network_id4" type="hidden" value="4" /> Actual result: -------------- Desired result: $form['hidden']['network_id1']['html'] = <input name="network_id1" type="hidden" value="1" /> $form['hidden']['network_id2']['html'] = <input name="network_id2" type="hidden" value="1" /> $form['hidden']['network_id3']['html'] = <input name="network_id3" type="hidden" value="1" /> $form['hidden']['network_id4']['html'] = <input name="network_id4" type="hidden" value="1" />

Comments

 [2008-11-19 13:42 UTC] avb (Alexey Borzov)
The Array renderer has $collectHidden constructor parameter that will toggle exactly this behaviour. No idea why ArraySmarty forces that to true, need to investigate further.
 [2009-01-15 20:05 UTC] ivanbarrios (Ivan Barrios)
Yes, in fact, line 140 of ArraySmarty.php calls HTML_Quickform_Renderer(true, $staticLabels); If you change the 'true' to 'false' the SmartyArray renderer will generate the hidden elements as sub-arrays of the overall quickform array. (I believe this is intended as the default behavior of the renderer)
 [2009-04-06 18:02 UTC] avb (Alexey Borzov)
-Status: Analyzed +Status: Closed
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.