/** * Form * ==== */ class Form { private $form, $cntField, $cntFilled, $cntValid, $formValid ; private $msg, $tabMsg = array( VIDE => "Prêt à recevoir l'encodade de votre formulaire" , KO => "Veuillez corriger les fautes/complètez votre formulaire" , OK => "Parfait, pas(plus) d'erreur(s) dans ce formulaire" ) ; function __construct($form) { $this->form = $form ; $this->cntField = count($this->form) ; $this->formValid = false ; $this->cntValid = 0 ; $this->stack = new Stack() ; } function Validate() { // // Error Handler // ============= // try { $this->cntFilled = 0 ; $this->cntValid = 0 ; for($i = 0 ; $i < $this->cntField ; $i++) { if ($this->form[$i] instanceof Validator) if ($this->form[$i]->Filled() ) { $this->cntFilled++ ; if ($this->form[$i]->Validate() ) $this->cntValid++ ; } else { $msg = $this->form[$i]->mustFill() ; if ($msg) Stack::stackMessage($msg) ; } } if ($this->cntFilled == 0) $this->msg = VIDE ; elseif ($this->cntFilled < $this->cntField) $this->msg = KO ; elseif ($this->cntFilled == $this->cntField) $this->msg = OK ; user_error("Form fields[".$this->cntField."] filled[".$this->cntFilled."]" , E_USER_NOTICE) ; // } catch (Exception $E) // { Exception::exception_handler($E) ; } } function __destruct() { } // ================================== // All Error Stacking functions // ================================== public function getStackError() // Public car function appelée du formulaire... { return(Stack::getStackError() ) ; } protected function getCntStack() { return(Stack::cntStack) ; } protected function stackMessage($msg) { return(Stack::stackMessage($msg)) ; } // ================================== public function getCntField() { return($this->cntField) ; } public function getCntFilled() { return($this->cntFilled) ; } public function isFormValid() { return(Stack::getCntStack() == 0) ; } // All Screen message area routines // ================================== public function getMsg() // Public car function appelée du formulaire... { return( $tabMsg[$this->msg] ) ; } // ================================== }