validated = true; $this->pageId = 'Page#'.$pageId; $this->validating = false; $this->currentPage = ''; } /** * Validation si la page est concernée * */ function visitPage(Page $comp, $level) { if ($this->validating == true) { if ($comp->id != $this->currentPage) { $this->validating = false; } } elseif ($comp->id == $this->pageId) { $this->validating = true; //echo"
En validation (".$this->pageId.") ..."; } $this->currentPage = $comp->id; } public function visitField(Field $comp, $level) { if ($this->validating == true && $comp->type != 'Fieldset' && $comp->type != 'Fieldset_end' && $comp->type != 'Hidden' && $comp->type != 'Submit' && $comp->type != 'Comment') { //echo "
Ce champ a pour Required = ".$comp->required; if ($this->fieldValidation(&$comp) !== true) { //echo "
Erreur sur ".$comp->name." (valeur actuelle : ".$comp->value.")
"; $this->validated = false; } } } public function isValid() { if ($this->validated == true) { return true; } else { return false; } } /** * Validation de la valeur du champ */ private function fieldValidation($field) { //echo "
Validation pour ".$field->label.""; $field->fieldErrors = array(); // reset du tableau des erreurs pour ce champ switch($field->type) { // en fonction du type de champ case ($field->type == 'Text' || $field->type == 'Password' || $field->type == 'Linked_1-n') : if ($field->required == true) { // champ obligatoire ? if(trim($field->value) == '') { array_push($field->fieldErrors,"Valeur obligatoire"); } } if (trim($field->okValues) != '') { // valeurs restreintes ? if(!in_array(trim($field->value), explode($field->okValues))) { array_push($field->fieldErrors,"Valeur non autorisée"); } } if (trim($field->validIf) != '') { $Crits = explode( $field->valueSep, trim($field->validIf) ); foreach( $Crits as $value ) { switch($value) { case 'email' : // format email valide if(!ereg ("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $field->value)) { array_push($field->fieldErrors,"Format invalide"); } break; case 'age' : // âge plausible if(!(is_numeric($field->value) && $field->value >= 0 && $field->value < 999)) { array_push($field->fieldErrors,'Ce champ doit contenir un âge valide (en années)'); } break; case substr($value, 0, 3) == 'max' : // long. max if(strlen($field->value) > $this->maxLength($field->validIf)) { array_push($field->fieldErrors,'maximum '.$this->maxLength($field->validIf).' caractères'); } break; case substr($value, 0, 3) == 'min' : // long. min if(strlen($field->value) < $this->minLength($field->validIf)) { array_push($field->fieldErrors,'minimum '.$this->minLength($field->validIf).' caractères'); } break; case 'int' : // entier if(!(is_numeric($field->value) && is_integer($field->value + 0))) { array_push($field->fieldErrors,'nombre entier requis'); } break; case 'float' : // decimal if(!(is_numeric($field->value) && is_float($field->value + 0))) { array_push($field->fieldErrors,'nombre décimal requis'); } break; default : break; } } } break; default : break; } return $validation = (sizeof($field->fieldErrors) > 0) ? false : true; } // Retourne la longueur max du champ si existante function maxLength($validIf) { $max = false; $tests = explode("|", $validIf); foreach ( $tests as $test ) { if (substr($test,0,3) == 'max' && is_numeric(substr($test, 3)) && substr($test, 3) >= 0 && substr($test, 3) <= 9999){$max = substr($test, 3);} } return $max; } // Retourne la longueur min du champ si existante function minLength($validIf) { $min = false; $tests = explode("|",$validIf); foreach ( $tests as $test ) { if (substr($test,0,3) == 'min' && is_numeric(substr($test, 3)) && substr($test, 3) >= 0 && substr($test, 3) <= 9999){$min = substr($test, 3);} } return $min; } //Pas d'action sur ces composites function visitFormosite(Formosite $comp, $level) { return true; } function visitBlock(Block $comp, $level) { return true; } } ?>