/
kids_validate_class.php
executable file
·112 lines (89 loc) · 2.76 KB
/
kids_validate_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
////////////////////////////////////////////////////////////////////////////////
//Page : enfants_validate_class.php
//Auteur : Reno Wong
////////////////////////////////////////////////////////////////////////////////
require_once ('config.php');
require_once ('decode_utf8.php');
class Validate {
private $mMysqli;
function __construct(){
$this->mMysqli = new mysqli(DBSERVER, DBUSER, DBPWD, DB);
}
function __destruct(){
$this->mMysqli->close();
}
public function ValidateAJAX($inputValue, $fieldID){
switch($fieldID){
case 'txt_nom_enfant':
return $this->validateNom($inputValue);
$_SESSION['errors']['enfantNom'] = true;
break;
case 'txt_prenom_enfant':
return $this->validatePrenom($inputValue);
$_SESSION['errors']['enfantPrenom'] = true;
break;
case 'txt_dn_enfant':
return $this->validateDateNaissance($inputValue);
$_SESSION['errors']['enfantDN'] = true;
break;
case 'txt_cps_enfant':
return $this->validateCPS($inputValue);
$_SESSION['errors']['enfantCPS'] = true;
break;
//case 'txt_classe_enfant':
//return $this->validateClasse($inputValue);
//break;
}
}
public function ValidatePHP(){
$errorExist = 0;
if(!$this->validateNom($_POST['txt_nom_enfant'])){
$errorExist = 1;
$_SESSION['errors']['enfantNom'] = true;
}
if(!$this->validatePrenom($_POST['txt_prenom_enfant'])){
$errorExist = 1;
$_SESSION['errors']['enfantPrenom'] = true;
}
if(!$this->validateDateNaissance($_POST['txt_dn_enfant'])){
$errorExist = 1;
$_SESSION['errors']['enfantDN'] = true;
}
if(!$this->validateCPS($_POST['txt_cps_enfant'])){
$errorExist = 1;
$_SESSION['errors']['enfantCPS'] = true;
}
//if(!$this->validateClasse($_POST['txt_classe_enfant'])){
// $errorExist = 1;
//}
if($errorExist == 0){
return true;
} else {
return false;
}
}
private function validateNom($value) {
$value = decode_utf8($value);
//return (!preg_match('/^[A-Za-z]{1,}[\-\ ]?[A-Za-z]{1,}[\-\ ]?[A-Za-z]{1,}$/i', $value)) ? 0 : 1;
return (!preg_match('/^[A-Za-z]{1,}[\-\ ]?[A-Za-z]*[\-\ ]?[A-Za-z]*$/i', $value)) ? 0 : 1;
}
private function validatePrenom($value) {
$value = decode_utf8($value);
return (!preg_match("/^[A-Za-z]{1,}[\-\ \']?[A-Za-z]{1,}[\-\ \']?[A-Za-z]{1,}$/i", $value)) ? 0 : 1;
}
private function validateDateNaissance($value) {
if ($value==""){return 0;}else{return 1;}
//$date = explode("/", $value);
//return (checkdate($date[1], $date[0], $date[2])) ? 1 : 0;
}
private function validateCPS($value) {
//if ($value=='') return 0;
return (!preg_match('/^([0-9]{4}|[0-9]{7})$/', $value)) ? 0 : 1;
}
//private function validateClasse($value) {
// //if ($value=='') return 0;
// return (!preg_match('/^[a-z0-9]{1,}$/i', $value)) ? 0 : 1;
//}
}
?>