Permalink
Browse files

MDL-17151: Missing code to check for uniqueness of values

  • Loading branch information...
1 parent e870355 commit 418a1ffb392697b9063e5f45bf11b5c330eea725 ikawhero committed Nov 7, 2008
Showing with 11 additions and 2 deletions.
  1. +1 −0 lang/en_utf8/moodle.php
  2. +10 −2 user/profile/lib.php
View
@@ -1578,6 +1578,7 @@
$string['userzones'] = 'User zones';
$string['usethiscourse'] = 'Use this course';
$string['usingexistingcourse'] = 'Using existing course';
+$string['valuealreadyused'] = 'This value has already been used.';
$string['version'] = 'Version';
$string['view'] = 'View';
$string['views'] = 'Views';
View
@@ -108,8 +108,16 @@ function edit_save_data($usernew) {
* @return string contains error message otherwise NULL
**/
function edit_validate_field($usernew) {
- //no errors by default
- return array();
+ $errors = array();
+ /// Check for uniqueness of data if required
+ if ($this->is_unique()) {
+ if ($userid = get_field('user_info_data', 'userid', 'fieldid', $this->field->id, 'data', $usernew->{$this->inputname})) {
+ if ($userid != $usernew->id) {
+ $errors["{$this->inputname}"] = get_string('valuealreadyused');
+ }
+ }
+ }
+ return $errors;
}
/**

0 comments on commit 418a1ff

Please sign in to comment.