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

Bug #5269 default values ignored for select if any GET variable is set
Submitted: 2005-09-01 15:40 UTC
From: blaise at thauvin dot org Assigned: mansion
Status: Closed Package: HTML_QuickForm
PHP Version: 5.0.0 OS: Win 2K
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 9 + 19 = ?

 
 [2005-09-01 15:40 UTC] blaise at thauvin dot org
Description: ------------ The default value for a select box is ignored if the script is called with any GET variable set in the URL, even though the variable is not related to the select box. The problem only occurs with the GET method. Post method is OK. The problem appears with PHP 5.0 and 5.1 and Quickform 3.2.5 The short script attached demonstrates the problem. Test script: --------------- <?php require_once 'HTML/QuickForm.php'; $form = new HTML_QuickForm('bug','get'); $form->addElement('select','ID','ID', array(1=>'A', 2=>'B')); $form->setDefaults(array('ID' => '2')); echo $form->toHtml(); echo '<a href="http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'].'">OK, no get passed</a><BR>'; echo '<a href="http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'].'?BUG=2">KO, no get passed</a>'; ?> Expected result: ---------------- The script shows a page with a two lines select box. The second line is selected as the default value. The two links provided in the page are almost similar. One passes a variable as a GET, the other doesn't. They both point at the script. The page should reprint with the same default values. It doesn't. Replace the GET method with POST and the problem is gone (but this is not an option for me)

Comments

 [2005-09-22 18:27 UTC] pear at iantomey dot com
yeah I just found this on upgrade to 3.2.5. its because _flagSubmitted is set during the form constructor and is set if there are any values set on the input. Now there is definately a problem here with multiple selects - it is impossible to distinguish if the value has not been submitted or whether there are no selections, but for single selects this is not the case, there will always be a value submitted if the form has been submitted by a browser. So I propose changing line 589 of select.php from if (null === $value && !$caller->isSubmitted()) { to if (null === $value && (!$caller->isSubmitted() || !$this->getMultiple()) ) { and updating the documentation in case anybody runs in the same thing with multiple selects. Perhaps another option is to make _flagSubmitted work with tracked submit.
 [2005-12-13 15:50 UTC] mansion at php dot net
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. I applied your changes to CVS. Thanks.