-
Notifications
You must be signed in to change notification settings - Fork 0
/
field.class.php
47 lines (41 loc) · 1.53 KB
/
field.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
class profile_field_regexp extends profile_field_base {
function edit_field_add($mform) {
$size = $this->field->param1;
$maxlength = $this->field->param2;
$regexp= $this->field->param3;
/// Create the form field
$mform->addElement('text', $this->inputname, format_string($this->field->name.' '.$regexp), 'maxlength="'.$size.'" size="'.$maxlength.'" ');
$mform->setType($this->inputname, PARAM_TEXT);
}
function edit_validate_field($usernew) {
$errors = array();
$errors = parent::edit_validate_field($usernew);
if (count($errors)==0) {
// 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 = '';
}
}
if ($value != ''){
$regexp= $this->field->param3;
$errmess= $this->field->param4;
$matches=array();
$status=preg_match($regexp, $value, $matches);
if ($status != 1 || ($status == 1 && $matches[0]!=$value)){
if ($errmess !=''){
$errors[$this->inputname] = $errmess;
} else {
$errors[$this->inputname] = get_string('err_regexp','profilefield_regexp');
}
}
}
return $errors;
}
}