$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"');
$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"');
$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'));
}
}
+ /**
+ * 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) {
/**
* 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.
*
/// 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)) {
$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
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);
}
}