Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 418a1ffb392697b9063e5f45bf11b5c330eea725 1 parent e870355
ikawhero authored
Showing with 11 additions and 2 deletions.
  1. +1 −0  lang/en_utf8/moodle.php
  2. +10 −2 user/profile/lib.php
View
1  lang/en_utf8/moodle.php
@@ -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
12 user/profile/lib.php
@@ -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;
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.