diff --git a/user/profile/index_category_form.php b/user/profile/index_category_form.php index 940e9a804ee..314ea917385 100644 --- a/user/profile/index_category_form.php +++ b/user/profile/index_category_form.php @@ -33,10 +33,19 @@ class category_form extends moodleform { $data = (object)$data; - $category = get_record('user_info_category', 'id', $data->id); + $duplicate = record_exists('user_info_category', 'name', $data->name); /// Check the name is unique - if ($category and ($category->name !== $data->name) and (record_exists('user_info_category', 'name', $data->name))) { + if (!empty($data->id)) { // we are editing an existing record + $olddata = get_record('user_info_category', 'id', $data->id); + // name has changed, new name in use, new name in use by another record + $dupfound = (($olddata->name !== $data->name) && $duplicate && ($data->id != $duplicate->id)); + } + else { // new profile category + $dupfound = $duplicate; + } + + if ($dupfound ) { $errors['name'] = get_string('profilecategorynamenotunique', 'admin'); }