diff --git a/course/edit_form.php b/course/edit_form.php index 6e4452dce59..ead6177d1cc 100644 --- a/course/edit_form.php +++ b/course/edit_form.php @@ -82,6 +82,7 @@ class course_edit_form extends moodleform { $mform->setType('fullname', PARAM_MULTILANG); if ($course and !has_capability('moodle/course:changefullname', $coursecontext)) { $mform->hardFreeze('fullname'); + $mform->setConstant('fullname', $course->fullname); } $mform->addElement('text','shortname', get_string('shortname'),'maxlength="100" size="20"'); @@ -91,6 +92,7 @@ class course_edit_form extends moodleform { $mform->setType('shortname', PARAM_MULTILANG); if ($course and !has_capability('moodle/course:changeshortname', $coursecontext)) { $mform->hardFreeze('shortname'); + $mform->setConstant('shortname', $course->shortname); } $mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100" size="10"'); @@ -98,6 +100,7 @@ class course_edit_form extends moodleform { $mform->setType('idnumber', PARAM_RAW); if ($course and !has_capability('moodle/course:changeidnumber', $coursecontext)) { $mform->hardFreeze('idnumber'); + $mform->setConstants('idnumber', $course->idnumber); } $mform->addElement('htmleditor','summary', get_string('summary'), array('rows'=> '10', 'cols'=>'65')); diff --git a/lib/formslib.php b/lib/formslib.php index 075a1cdf237..d9b55a51c77 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -1235,6 +1235,19 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless { } } + /** + * 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){ $unfiltered = array(); if (null === $elementList) { @@ -1645,8 +1658,8 @@ function validate_' . $this->_formName . '(frm) { /** * 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. * diff --git a/user/edit_form.php b/user/edit_form.php index e35b173ccfe..45282dc41bb 100644 --- a/user/edit_form.php +++ b/user/edit_form.php @@ -74,7 +74,6 @@ class user_edit_form extends moodleform { /// 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)) { @@ -83,13 +82,15 @@ class user_edit_form extends moodleform { $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 diff --git a/user/profile/lib.php b/user/profile/lib.php index 445155192f9..35107e35079 100644 --- a/user/profile/lib.php +++ b/user/profile/lib.php @@ -141,6 +141,7 @@ class profile_field_base { function edit_field_set_locked(&$mform) { if ($this->is_locked() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) { $mform->hardFreeze($this->inputname); + $mform->setConstant($this->inputname, $this->data); } }