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

Bug #14014 Selection Not Remembered on Failed Form Validation
Submitted: 2008-05-29 13:00 UTC
From: light461 Assigned:
Status: Open Package: HTML_QuickForm_altselect (version CVS)
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2008-05-29 13:00 UTC] light461 (Trevor Smith)
Description: ------------ When the form is submitted with the altselect object in it and validation fails on the form for any reason then when the form refreshes the previously selected values in the altselect object are not remembered. Test script: --------------- require_once 'HTML/QuickForm.php'; require_once 'HTML/QuickForm/altselect.php'; // Instantiate the HTML_QuickForm object $form = new HTML_QuickForm('OnlineGiving'); $element =& $form->addElement('altselect','amount','My gift amount: <em>(U.S. Dollars)</em>', array('1000' => '$1000', '500' => '$500', '250' => '$250', '100' => '$100', '50' => '$50'))); $element->setIncludeOther(true); $element->setSelected('Other Amount'); $form->addElement('submit', null, 'Review gift and enter payment information...'); // Define filters and validation rules $form->registerRule('donation','regex', '/^[\d\-\.\s]+$/'); $form->addRule('amount', 'Please provide a valid dollar amount.', 'donation'); $form->addRule('amount', 'Please provide a donation amount.', 'required'); function compare_field($element,$value,$arg) { global $form; if ($value == $form->getElementValue($arg)) { return true; } else { return false; } } // Try to validate a form if ($form->validate()) { //process data }else{ echo "<p>Cras dictum. Maecenas ut turpis. In vitae erat ac orci dignissim eleifend. Nunc quis justo. Sed vel ipsum in purus tincidunt pharetra. Sed pulvinar, felis id consectetuer malesuada, enim nisl mattis elit, a facilisis tortor nibh quis leo. </p>"; $form->display(); }; Expected result: ---------------- The previously submitted values remembered. Actual result: -------------- The altselect object returns to its default settings.

Comments

 [2008-05-29 13:49 UTC] shangxiao (David Sanders)
Thank you for taking the time to write to us, but this is not a bug. Please use $form->setDefaults(array('amount' => 'Other Amount')); rather than $element->setSelected(); See bug #13685
 [2008-05-29 14:07 UTC] light461 (Trevor Smith)
Thank you very much for clearing this up but you might want to update your example page as it indicates to do this the way I originally did.
 [2008-08-11 06:44 UTC] shangxiao (David Sanders)
Closed is for fixed bugs
 [2008-11-25 21:21 UTC] wiesemann (Mark Wiesemann)
(setting status back to "Open" and version number to "CVS")