Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 2.0
-
Fix Version/s: None
-
Component/s: Forms Library
-
Labels:None
-
Affected Branches:MOODLE_20_STABLE
Description
The problem :
when i used several 'choosecoursefile' element with an array of it, the return key of the value is for example :
file[0]
file[1]
and not an array of file.
The solution :
The problem is in the 'MoodleQuickForm_choosecoursefile' class with the function 'exportValue' (file : \lib\form\choosecoursefile.php).
The original code is :
#
function exportValue(&$submitValues, $assoc = false)
#
I proposed this modification wich works fine
#
function exportValue(&$submitValues, $assoc = false)
{
$value = null;
$valuearray = $this->_elements[0]->exportValue($submitValues[$this->getName()], true);
$name = $this->getName();
if (!strpos($name, '[')) {
$value[$this->getName()]=$valuearray['value'];
return $value;
} else {
$valueAry = array();
$myIndex = "['" . str_replace(array(']', '['), array('', "']['"), $name) . "']";
eval("\$valueAry$myIndex = \$valuearray['value'];");
return $valueAry;
}
}
#
We would have to consider this very carefully. Haven't looked in detail at the code yet but I don't think we need to use eval here do we? This could be a potential security hole. Better not to use eval even if the data is not coming from the user / browser IMHO.