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
|
function __construct($balise,$id,$fieldLabel,$name,$class,$string_condition){
$this->balise = $balise;
$this->id = $id.'_'.$name;
$this->name = $name;
$this->class = $class;
$this->fieldLabel = $fieldLabel;
if(is_int($string_condition)){
$this->mandatory = $string_condition;
}elseif(empty($string_condition)){
echo $_SESSION[$name]['fieldLabel'] = $this->fieldLabel;
}else{
// Liste des conditions possibles
$validCondition = array(
'isNotEmpty',
'isEmail',
'isString',
'isStringOnly',
'isDate',
'isNumeric',
'minDigit', // (minDigir:5) Doit avoir au moins 5 caracteres
'maxDigit', // (maxDigit:5) Doit avoir max 5 caractères
'nbDigit', // (digit:5) doit avoir 5 caractere
'removeAccent',
'strip_tags', // strip_tags:[br],[hr],[p]
'captcha'
);
//Place les conditions sous forme d'array
$array_condition = explode(',',$string_condition);
// Parcours le tableau et liste les condition
//$this->toValidates[$name]=array();
foreach ($array_condition as $key => $condition){
//Créée un nouvelle array afin de départager les conditions qui ont une valeur. Expl: minDigit:8
$_condition = explode(":",$condition);
if(!in_array($_condition[0],$validCondition)){
echo $name.': ['.$_condition[0].'] is not valid. ';
}else{
$_condition0 = $_condition[0];
if(isset($_condition[1])) $_condition1 = ':'.$_condition[1];
else $_condition1= "";
$this->toValidate['conditions'][]=$_condition0.$_condition1;
}
}
$_SESSION[$this->name] = $this->toValidate;
$_SESSION[$this->name]['fieldLabel'] = $this->fieldLabel;
#print_r($_SESSION[$this->name]);
#echo '<hr>';
}
} |
Partager