MDL-16839 forms: workaround for problematic hard frozen values; merged from MOODLE_1...
authorskodak <skodak>
Mon, 13 Oct 2008 19:39:27 +0000 (19:39 +0000)
committerskodak <skodak>
Mon, 13 Oct 2008 19:39:27 +0000 (19:39 +0000)
course/edit_form.php
lib/formslib.php
user/edit_form.php
user/profile/lib.php

index 6e4452dce59f47907b8c66ea6c43fc06b8e95840..ead6177d1cc307ef95f1825346d3f6161d6642df 100644 (file)
@@ -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'));
index 075a1cdf2377e2816cedcf301aebf5562aa974b1..d9b55a51c77c1c6801ebd0ae57ff2300366ff810 100644 (file)
@@ -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.
      *
index e35b173ccfe58786b4ce048404030501ca5f67e4..45282dc41bb44db468cae959c249a4fe5bd24ce7 100644 (file)
@@ -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
index 445155192f962d56f0f7c9d0816573e438f5ac2a..35107e3507982773a0f8957f3b1572a981fc4190 100644 (file)
@@ -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);
         }
     }