Skip to content

Commit

Permalink
MDL-37339 Administration: Unique custom profile should not be checked…
Browse files Browse the repository at this point in the history
… if it's empty.

Currently we have two options for custom profile fields 'Unique' and 'Required'
If value s not entered for unique and not required field then we should allow
duplicate empty values. If value is entered then we should check for unique input.
In case field is unique and required then it should be always checked as required
field can't be empty.
  • Loading branch information
Rajesh Taneja committed Jan 16, 2013
1 parent 2713f92 commit b3f92c0
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions user/profile/lib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -129,9 +129,19 @@ function edit_validate_field($usernew) {
global $DB; global $DB;


$errors = array(); $errors = array();
/// Check for uniqueness of data if required // Get input value.
if ($this->is_unique()) { if (isset($usernew->{$this->inputname})) {
$value = (is_array($usernew->{$this->inputname}) and isset($usernew->{$this->inputname}['text'])) ? $usernew->{$this->inputname}['text'] : $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(' $data = $DB->get_records_sql('
SELECT id, userid SELECT id, userid
FROM {user_info_data} FROM {user_info_data}
Expand Down

0 comments on commit b3f92c0

Please sign in to comment.