diff --git a/user/profile/lib.php b/user/profile/lib.php index fd30d581180..8b8ee4dfbe0 100644 --- a/user/profile/lib.php +++ b/user/profile/lib.php @@ -129,9 +129,19 @@ class profile_field_base { global $DB; $errors = array(); - /// Check for uniqueness of data if required - if ($this->is_unique()) { - $value = (is_array($usernew->{$this->inputname}) and isset($usernew->{$this->inputname}['text'])) ? $usernew->{$this->inputname}['text'] : $usernew->{$this->inputname}; + // Get input value. + if (isset($usernew->{$this->inputname})) { + if (is_array($usernew->{$this->inputname}) && isset($usernew->{$this->inputname}['text'])) { + $value = $usernew->{$this->inputname}['text']; + } else { + $value = $usernew->{$this->inputname}; + } + } else { + $value = ''; + } + + // Check for uniqueness of data if required. + if ($this->is_unique() && (($value !== '') || $this->is_required())) { $data = $DB->get_records_sql(' SELECT id, userid FROM {user_info_data}