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 #2785

Element's values not extracted if their names contain spaces

Details

Submitted2004-11-18 15:30 UTC
Frommichael dot caplan at lechateau dot ca
StatusWont fix
PackageHTML_QuickForm
PHP Version5.0.2
OSRHE 3
Roadmaps(Not assigned)

Comments

[2004-11-18 15:30 UTC] michael dot caplan at lechateau dot ca

Description:
------------
When creating groups of elements, if the group name has a space in it (eg: 'postings group'), exportValues() fails to retreive the submitted values for the group. It appears that PHP operates on the submitted variables by replacing all spaces in posted variables with an underscore (eg: 'postings group[en]' becomes 'postings_group[en]'). While perhaps it is true that it is bad form to allow spaces in the group name al together, in this case I do not have a choice.

Ideally, QuickForms should include another level of posted request checking if it failes to retreive the results from the posted form: check for the results of the group with spaces replaced wiht underscores. Otherwise, all posted materail defaults to the originally bound form data and posted material is lost.

Here is a fix to elements.php to consider:

/**
* Tries to find the element value from the values array
*
* @since 2.7
* @access private
* @return mixed
*/
function _findValue(&$values)
{
if (empty($values)) {
return null;
}

$elementName = $this->getName();

if (isset($values[$elementName])) {
return $values[$elementName];
} elseif (strpos($elementName, '[')) {
$myVar = "['" . str_replace(array(']', '['), array('', "']['"), $elementName) . "']";
$result = eval("return (isset(\$values$myVar)) ? \$values$myVar : null;");
if (empty($result) && strpos($elementName, ' ')) {
$myVar = str_replace(' ', '_', $myVar);
$result = eval("return (isset(\$values$myVar)) ? \$values$myVar : null;");
}
return $result;
} else if (strpos($elementName, ' ')) {
$elementName = str_replace(' ', '_', $elementName);
return (isset($values[$elementName])) ? $values[$elementName] : null ;
} else {
return null;
}
} //end func _findValue

Thanks,

Michael

[2004-11-29 17:59 UTC] michael dot caplan at lechateau dot ca

Sorry, don't follow. What do you mean by fix summary. Is the patch good (minus the other places where such a fix might be needed)? It is working great for me, but I am not awair of other places where such a fix might be required.