Permalink
Browse files

Merge branch 'MDL-36760_23' of git://github.com/timhunt/moodle into M…

…OODLE_23_STABLE
  • Loading branch information...
2 parents 55f8a9c + 500c73b commit 4c14127cdbeb97c1cf3f4d45f925616638b97c85 Sam Hemelryk committed Nov 26, 2012
Showing with 24 additions and 1 deletion.
  1. +24 −1 lib/formslib.php
View
@@ -1702,7 +1702,7 @@ function exportValues($elementList = null){
$value = '';
// If we have a default value then export it.
if (isset($this->_defaultValues[$varname])) {
- $value = array($varname => $this->_defaultValues[$varname]);
+ $value = $this->prepare_fixed_value($varname, $this->_defaultValues[$varname]);
}
} else {
$value = $this->_elements[$key]->exportValue($this->_submitValues, true);
@@ -1733,6 +1733,29 @@ function exportValues($elementList = null){
return $unfiltered;
}
+ /**
+ * This is a bit of a hack, and it duplicates the code in
+ * HTML_QuickForm_element::_prepareValue, but I could not think of a way or
+ * reliably calling that code. (Think about date selectors, for example.)
+ * @param string $name the element name.
+ * @param mixed $value the fixed value to set.
+ * @return mixed the appropriate array to add to the $unfiltered array.
+ */
+ protected function prepare_fixed_value($name, $value) {
+ if (null === $value) {
+ return null;
+ } else {
+ if (!strpos($name, '[')) {
+ return array($name => $value);
+ } else {
+ $valueAry = array();
+ $myIndex = "['" . str_replace(array(']', '['), array('', "']['"), $name) . "']";
+ eval("\$valueAry$myIndex = \$value;");
+ return $valueAry;
+ }
+ }
+ }
+
/**
* Adds a validation rule for the given field
*

0 comments on commit 4c14127

Please sign in to comment.