Permalink
Browse files

MDL-16839 forms: workaround for problematic hard frozen values; merge…

…d from MOODLE_19_STABLE
  • Loading branch information...
skodak
skodak committed Oct 13, 2008
1 parent 9330f3e commit d19db94df3cefad8b1098675e3107c1e8f252c35
Showing with 21 additions and 6 deletions.
  1. +15 −2 lib/formslib.php
  2. +5 −4 user/edit_form.php
  3. +1 −0 user/profile/lib.php
View
@@ -880,6 +880,19 @@ function setHelpButton($elementname, $button, $suppresscheck=false, $function='h
}
}
+ /**
+ * Set constant value not overriden by _POST or _GET
+ * note: this does not work for complex names with [] :-(
+ * @param string $elname name of element
+ * @param mixed $value
+ * @return void
+ */
+ function setConstant($elname, $value) {
+ $this->_constantValues = HTML_QuickForm::arrayMerge($this->_constantValues, array($elname=>$value));
+ $element =& $this->getElement($elname);
+ $element->onQuickFormEvent('updateValue', null, $this);
+ }
+
function exportValues($elementList= null, $addslashes=true){
$unfiltered = array();
if (null === $elementList) {
@@ -1282,8 +1295,8 @@ function _registerCancelButton($addfieldsname){
/**
* Displays elements without HTML input tags.
* This method is different to freeze() in that it makes sure no hidden
- * elements are included in the form. And a 'hardFrozen' element's submitted value is
- * ignored.
+ * elements are included in the form.
+ * Note: If you want to make sure the submitted value is ignored, please use setDefaults().
*
* This function also removes all previously defined rules.
*
View
@@ -68,7 +68,6 @@ function definition_after_data() {
/// disable fields that are locked by auth plugins
$fields = get_user_fieldnames();
- $freezefields = array();
$authplugin = get_auth_plugin($user->auth);
foreach ($fields as $field) {
if (!$mform->elementExists($field)) {
@@ -77,13 +76,15 @@ function definition_after_data() {
$configvariable = 'field_lock_' . $field;
if (isset($authplugin->config->{$configvariable})) {
if ($authplugin->config->{$configvariable} === 'locked') {
- $freezefields[] = $field;
+ $mform->hardFreeze($field);
+ $mform->setConstant($field, $user->$field);
} else if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $user->$field != '') {
- $freezefields[] = $field;
+ $mform->hardFreeze($field);
+ $mform->setConstant($field, $user->$field);
}
}
}
- $mform->hardFreeze($freezefields);
+
}
/// Next the customisable profile fields
View
@@ -139,6 +139,7 @@ function edit_field_set_required(&$mform) {
function edit_field_set_locked(&$mform) {
if ($this->is_locked() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
$mform->hardFreeze($this->inputname);
+ $mform->setConstant($this->inputname, $this->data);
}
}

0 comments on commit d19db94

Please sign in to comment.