-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfield.class.php
71 lines (63 loc) · 1.95 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
include 'controlla_cf.php' ;
class profile_field_codicefiscale extends profile_field_base {
/**
* Overwrite the base class to display the data for this field
*/
function edit_save_data_preprocess($data, $datarecord) {
return strtoupper($data);
}
function edit_field_add($mform) {
/// Create the form field
$mform->addElement('text', $this->inputname, format_string($this->field->name), 'maxlength="16" size="16" style="width:16em" ');
$mform->setType($this->inputname, PARAM_TEXT);
/*
if ($this->is_required() and !has_capability('moodle/user:update', context_system::instance())) {
$mform->addRule($this->inputname, get_string('required'), 'nonzero', null, 'client');
}
*/
}
/**
* Overwrite the base class to validate this field
*/
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 = '';
}
$esito = controllaCF($value);
/* * 0 -> CF OK
* 1 -> stringa vuota
* 2 -> errore lunghezza CF
* 3 -> caratteri non previsti
* 4 -> controcodice sbagliato
*/
switch($esito) {
case 0:
break;
case 1:
$errors[$this->inputname] = get_string('cf_novalue','profilefield_codicefiscale');
break;
case 2:
$errors[$this->inputname] = get_string('cf_valuestrlen','profilefield_codicefiscale');
break;
case 3:
$errors[$this->inputname] = get_string('cf_valuestrchar','profilefield_codicefiscale');
break;
case 4:
$errors[$this->inputname] = get_string('cf_valuestrctrl','profilefield_codicefiscale');
break;
}
}
return $errors;
}
}