|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-05-21 18:49 UTC] nlenz at ivcf dot org
Description of problem:
1. $_POST["someUnrelatedVar"] is set.
2. Create a QuickForm object using POST
3. Call setDefaults()
4. Default values will not show up, even though the element's name was not set in $_POST.
Solution:
In the element.php file, onQuickFormEvent method.
Change:
if (isset($caller->_submitValues) && count($caller->_submitValues) > 0) {
To:
if (isset($caller->_submitValues) && count($caller->_submitValues) > 0 && $this->_findValue($caller->_submitValues) != null) {
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 08 15:00:02 2026 UTC |
I think the current behaviour of QuickForm checkboxes is still not using default values for checkboxes when it should be. The following code run on PHP 4.3.1 with version 3.0 of HTML_QuickForm ($Id: checkbox.php,v 1.14 2003/05/16 17:21:10 avb Exp $) ========script1.php========I think the current behaviour of QuickForm checkboxes is still not using default values for checkboxes when it should be. The following code run on PHP 4.3.1 with version 3.0 of HTML_QuickForm ($Id: checkbox.php,v 1.14 2003/05/16 17:21:10 avb Exp $) results in both checkboxes being displayed unchecked. To reproduce, open form1.php in browser, submit the form and form2.php will be displayed with both check boxes unticked. Opening script2.php directly (without POST data) will result in the first checkbox being checked (correct behavour). ========form1.php======== <html> <body> <form action="form2.php" method="post"> <input name="foo" value="random data" type="hidden"> <input name="send" value="Send" type="submit"> </form> </body> </html> ========form2.php======== <?php require_once ("HTML/QuickForm.php"); $form = new HTML_QuickForm('frmTest', 'post'); $form->addElement('checkbox', 'test1', 'Test 1:'); $form->addElement('checkbox', 'test2', 'Test 2:'); $defaultVals['test1'] = true; $defaultVals['test2'] = false; $form->setDefaults($defaultVals); $form->display(); ?> As I understand it a possialbe fix would be to apply the following patch to checkbox.php,v 1.14. As I do not fully understand QuickForm there may be reasons why this patch is a bad idea. Email me if you wish to dicuss the patch further. I am very impressed with the quality of HTML_QuickForm and would like to assist you in making it even better. Peter Jackson ========Proposed Patch======== --- checkbox.php Sun Jul 13 19:18:11 2003 +++ checkbox.php.mod Sun Jul 13 19:18:11 2003 @@ -257,9 +257,10 @@ // default values are overriden by submitted $value = $this->_findValue($caller->_constantValues); if (null === $value) { - // if no boxes were checked, then there is no value in the array - // yet we don't want to display default value in this case - if (isset($caller->_submitValues) && 0 < count($caller->_submitValues)) { + // use the submitted value only if a value of the + // same name was submitted, otherwise use default + if (isset($caller->_submitValues) && 0 < count($caller->_submitValues) + && $this->_findValue($caller->_submitValues) !== null) { $value = $this->_findValue($caller->_submitValues); } else { $value = $this->_findValue($caller->_defaultValues);