Bug #23746 Default values do not work when $_POST is set
| From: | Peter Jackson | Date: | Sat, 02 Aug 2003 17:41:46 +0000 |
| Subject: | Bug #23746 Default values do not work when $_POST is set | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-19151@lists.php.net to get a copy of this message | ||
I've added the following comment to Bug #23746:
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
behaviour).
========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 possible fix would be to apply the attached 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 discuss the patch further.
I am very impressed with the quality of HTML_QuickForm and would like to
assist you in making it even better.
Thanks
Peter Jackson