From 093c3b907b2630468286f6354958e72eb89c0096 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Fri, 1 Feb 2008 17:19:33 +0000 Subject: [PATCH] Change some conditions to properly check if the custom-profile-field really is using a duplicate shortname. MDL-13288 ; merged from 19_STABLE --- user/profile/definelib.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/user/profile/definelib.php b/user/profile/definelib.php index 38fc90e50e..937cdd4a96 100644 --- a/user/profile/definelib.php +++ b/user/profile/definelib.php @@ -89,21 +89,26 @@ class profile_define_base { * @return array associative array of error messages */ function define_validate_common($data, $files) { + global $USER; - + $err = array(); /// Check the shortname was not truncated by cleaning if (empty($data->shortname)) { $err['shortname'] = get_string('required'); + } else { + /// Fetch field-record from DB + $field = get_record('user_info_field', 'shortname', $data->shortname); /// Check the shortname is unique - } else if (($field = get_record('user_info_field', 'shortname', $data->shortname)) and ($field->id <> $data->id)) { - $err['shortname'] = get_string('profileshortnamenotunique', 'admin'); + if ($field and $field->id <> $data->id) { + $err['shortname'] = get_string('profileshortnamenotunique', 'admin'); /// Shortname must also be unique compared to the standard user fields - } else if (isset($USER->{$data->shortname})) { - $err['shortname'] = get_string('profileshortnamenotunique', 'admin'); + } else if (!$field and isset($USER->{$data->shortname})) { + $err['shortname'] = get_string('profileshortnamenotunique', 'admin'); + } } /// No further checks necessary as the form class will take care of it -- 2.39.5