Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-21767 fixed input validation

  • Loading branch information...
commit 9770907db38aae67c2d07a09a41b42772e5b5e2c 1 parent 668f994
@skodak skodak authored
Showing with 35 additions and 0 deletions.
  1. +35 −0 lib/form/select.php
View
35 lib/form/select.php
@@ -122,5 +122,40 @@ function getElementTemplateType(){
return 'default';
}
}
+ /**
+ * We check the options and return only the values that _could_ have been
+ * selected. We also return a scalar value if select is not "multiple"
+ */
+ function exportValue(&$submitValues, $assoc = false)
+ {
+ if (empty($this->_options)) {
+ return $this->_prepareValue(null, $assoc);
+ }
+
+ $value = $this->_findValue($submitValues);
+ if (is_null($value)) {
+ $value = $this->getValue();
+ }
+ $value = (array)$value;
+
+ $cleaned = array();
+ foreach ($value as $v) {
+ foreach ($this->_options as $option) {
+ if ((string)$option['attr']['value'] === (string)$v) {
+ $cleaned[] = (string)$option['attr']['value'];
+ break;
+ }
+ }
+ }
+
+ if (empty($cleaned)) {
+ return $this->_prepareValue(null, $assoc);
+ }
+ if ($this->getMultiple()) {
+ return $this->_prepareValue($cleaned, $assoc);
+ } else {
+ return $this->_prepareValue($cleaned[0], $assoc);
+ }
+ }
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.