PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_QuickForm » Bug #1723

Default Value is not used in checkbox if $_POST already set

Details

Request #1723Default Value is not used in checkbox if $_POST already set
Submitted2004-06-25 23:03 UTC
Fromtdr32 at cs dot byu dot edu
StatusWont fix
PackageHTML_QuickForm
PHP Version4.3.2
OSFedora Core 2
Roadmaps(Not assigned)

Comments

[2004-06-25 23:03 UTC] tdr32 at cs dot byu dot edu

Description:
------------
I am testing out a page to create forms where it will call a database with a username that was posted from a previos form, not QuickForm. When this value is in the $_POST array, my checkboxes won't care about the default values for them. They never become checked.

Reproduce code:
---------------
$_POST['username'] = 'me';

// create page with checkbox 'nolimit'
$controller->setDefaults('nolimit'=>'1');

// run the page

I fixed the problem in my version by modifying checkbox.php in onQuickFormEvent
if (null === $value) {
if (isset($caller->_submitValues) && 0 < count($caller->_submitValues)) {
$value = $this->_findValue($caller->_submitValues);
}
// before, this was an else statement
if ($value === null) {
$value = $this->_findValue($caller->_defaultValues);
}
}

Expected result:
----------------
The checkbox should be checked

Actual result:
--------------
The checkbox is not checked.

[2004-06-29 15:21 UTC] tdr32 at cs dot byu dot edu

I know that my "fix" created that problem. But I was just trying to find out the reason behind the behaviour and found that one. I don't exactly know a good fix for the behavior except for me to make sure that I never access the page with any elements in the post or get array, or I unset those arrays before calling HTML_QuickForm.

[2004-06-29 16:26 UTC] tdr32 at cs dot byu dot edu

Allright, I tried my idea of just making sure that I unset $_POST before I called HTML_QuickForm but I was still having a problem with my default value showing up. By the way, I upgraded HTML_QuickForm. So I looked at checkbox.php again (in the upgraded source, without my "fix") and in onQuickFormEvent I changed isset($caller->_submitValues) to is_array($caller->_submitValues), since _submitValues will always be an array if it has values (since it is just a copy of $_POST or $_GET). I did this because $caller->_submitValues was always set, even if $_POST was unset because I have magic_quotes on and so when it does the _recursiveFilter (in QuickForm.php) it creates a dummy array that is set. This fixed my problem so far.