Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…OODLE_22_STABLE
  • Loading branch information...
commit d6347b056df3276710c14ced12ca89ecf2d49af7 2 parents f3fc480 + 35314e2
@samhemelryk samhemelryk authored
Showing with 24 additions and 1 deletion.
  1. +24 −1 lib/formslib.php
View
25 lib/formslib.php
@@ -1670,7 +1670,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);
@@ -1701,6 +1701,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
*
* If the element is in fact a group, it will be considered as a whole.
Please sign in to comment.
Something went wrong with that request. Please try again.