Bonjour,

Ce pb est du type syntaxe et/ou architecture de classe en PHP 5 !
J'ai un formulaire que je souhaite valider.
Je me crée un script de validation que je pourrais réuitiliser autre part !
J'ai toute une série de classe mais celles qui nous importe pour l'instant sont:

CheckForm - pas besoin d'explication
Text et Interger - des champs du formulaire
Stack, qui me posait des problèmes.
Je l'ai donc intégrée à CheckForm !
Cette classe était pourtant instancée par Chekform et est susceptible de recevoir mes msgs d'erreur générées par les classes Filles (Text & Integer)

Entre chaque champ, il apparait que le stack est raz (remis à zéro)
Donc, dans mon formuaire, j'affiche juste un texte et [0]

voici ma classe CheckForm:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
   	class Checkform
		{	protected $stackMsg = array();
			protected $cntStack = 0 ;
			private $msg, $form, $cntField, $cntFilled, $valid ;
 
			function __construct($form)
			{	
user_error("Start of Constructor[".$this->getCntStack()."]" , E_USER_NOTICE) ;
 
				$this->initForm($form) ;
 
//
//              Error Handler
//				=============				
				try {
					$this->Validate() ;
				}	catch (Exception $E)
					{	$this->exception_handler($E) ; }
#
#				Choix du message en fonction du nbre de champ remplit OUI || NON (qui sera délivré par getMessage)
#				==================================================================================================	
				$this->msg = new Message($this->getCntFilled(),$this->getCntField(),$this->isFormValid()) ;
user_error("End of Constructor[".$this->getCntStack()."]" , E_USER_NOTICE) ;	 
			}
 
//          ==================================	
//          All Stack routines			
//          ==================================	
//          ==================================	
//          All Error Stacking functions			
//          ==================================	
			function getCntStack()
			{	return($this->cntStack) ; }	
 
			public function getStackError() 				// Public car function appelée fu formulaire...
			{	
user_error("getStackError[".$this->cntStack."]" , E_USER_NOTICE) ;	 
				$str = "" ; 
print("getStackError ==>[".$this->cntStack."]") ;
//				print_r($this->stackMsg); 
				for ($i = 0 ; $i < $this->cntStack ; $i++)
					$str .= $this->stackMsg[$i] ;
				return($str) ; 
			}
 
			public function stackMessage($msg)
			{	$this->stackMsg[] = $msg . "<br>\n" ; 
				$this->cntStack++ ; 
user_error("+++++++ Stacking msg[".$this->cntStack."][".$msg."]" , E_USER_NOTICE) ;	 
print("Stacking[".$msg."] - cntStack[".$this->cntStack."]") ;
//				print_r($this->stackMsg); 
			}
 
			public function emptyStack()
			{	$this->cntStack = 0 ;
user_error("emptyStack[".$this->cntStack."]" , E_USER_NOTICE) ;	 
				$this->stackMsg = array() ;	 
			}
 
			public function printStack()
			{	
user_error("printStack[".$this->cntStack."]" , E_USER_NOTICE) ;
				for ($i = 0 ; $i < $this->cntStack ; $i++)
					user_error ("stack[".$this->cntStack."] - " . $this->stackMsg[$i] , E_USER_NOTICE) ;
			}
 
//          ==================================	
//          All Screen message area routines			
//          ==================================	
			public function getMessage()                   // Public car function appelée fu formulaire...
			{	return($this->msg->getMessage()) ;  	}
 
			public function isFormValid()
			{	return($this->formValid) ; }
//          ==================================	
 
			private function getCntField()
			{ 	return($this->cntField) ;	}
 
			private function getCntFilled()
			{ 	return($this->cntFilled) ;	}
 
			private function initForm($form)
			{   $this->form  	  = $form ;
				$this->cntField   = count($this->form);
				$this->formValid  = false ;
				$this->emptyStack() ;
			}
 
			function Validate()
			{	$this->cntFilled = 0 ;
user_error("Start of Validation ==> cntStack[".$this->getCntStack()."]" , E_USER_NOTICE) ;	 
				for($i = 0 ; $i < $this->getCntField() ; $i++) 
				{	if ($this->form[$i] instanceof Validator)
//						if ($this->form[$i]->Filled() )
							{	
user_error("Start Validating field[".$i."]  cntStack[".$this->getCntStack()."]" , E_USER_NOTICE) ;
								$this->cntFilled++ ;
								$this->form[$i]->Validate() ; 				
								$this->printStack() ;
user_error("End   Validating field[".$i."]  cntStack[".$this->getCntStack()."]" , E_USER_NOTICE) ;
							}
				}
//user_error("End of Validate ==> cntStack[".Stack::getCntStack()."]" , E_USER_NOTICE) ;	 
			}
//
//          Error Handler Processing
//			========================	
			private function exception_handler($E)
			{	$T = $E->getTrace() ; 
			//	======================================================================
				print("FORM Validator error diagnostic" .  "<br>\n") ;
				print("=======================" .  "<br>\n") ;
 				print("Message: " . $E->getMessage() . " - File: " . $E->getFile() . " - Line: " . $E->getLine() . "<br>\n") ;
				print("<br>\n") ;
				print("Trace: " . "<br>\n") ;
				print("------ " . "<br>\n") ;
				print( "   => File               : " . $T[0]["file"]     . "<br>\n") ;
				print( "   => calling instruction: " . $T[0]["line"]     . "<br>\n") ;
 				print( "   => error class        : " . $T[0]["class"]    . "<br>\n") ;
				print( "   => error function     : " . $T[0]["function"] . "<br>\n") ;
				//	======================================================================
				user_error("Connexion error in File: (" . $E->getFile() . ") - line: (" . $E->getLine() . ")" , E_USER_WARNING) ;  
   			}
//	
//      End of class CheckForm
//		======================		
		}
Voici le log PHP:


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[28-May-2010 13:17:05] PHP Notice:  Start of Constructor[0] in F:\WebSites\test\checkform.php on line 644
[28-May-2010 13:17:05] PHP Notice:  emptyStack[0] in F:\WebSites\test\checkform.php on line 692

[28-May-2010 13:17:05] PHP Notice:  Start of Validation ==> cntStack[0] in F:\WebSites\test\checkform.php on line 728
[28-May-2010 13:17:05] PHP Notice:  Start Validating field[0]  cntStack[0] in F:\WebSites\test\checkform.php on line 733

[28-May-2010 13:17:05] PHP Notice:  +++++++ Stacking msg[1][Le champ[prenom] doit avoir une longueur comprise entre 3 et 30] in F:\WebSites\test\checkform.php on line 685
[28-May-2010 13:17:05] PHP Notice:  printStack[0] in F:\WebSites\test\checkform.php on line 698
[28-May-2010 13:17:05] PHP Notice:  End   Validating field[0]  cntStack[0] in F:\WebSites\test\checkform.php on line 737

[28-May-2010 13:17:05] PHP Notice:  Start Validating field[1]  cntStack[0] in F:\WebSites\test\checkform.php on line 733
[28-May-2010 13:17:05] PHP Notice:  +++++++ Stacking msg[1][Le champ[nom] doit avoir une longueur comprise entre 3 et 30] in F:\WebSites\test\checkform.php on line 685
[28-May-2010 13:17:05] PHP Notice:  printStack[0] in F:\WebSites\test\checkform.php on line 698
[28-May-2010 13:17:05] PHP Notice:  End   Validating field[1]  cntStack[0] in F:\WebSites\test\checkform.php on line 737

[28-May-2010 13:17:05] PHP Notice:  Start Validating field[2]  cntStack[0] in F:\WebSites\test\checkform.php on line 733
[28-May-2010 13:17:05] PHP Notice:  +++++++ Stacking msg[1][Valeur non numérique[4] [9999]] in F:\WebSites\test\checkform.php on line 685
[28-May-2010 13:17:05] PHP Notice:  printStack[0] in F:\WebSites\test\checkform.php on line 698
[28-May-2010 13:17:05] PHP Notice:  End   Validating field[2]  cntStack[0] in F:\WebSites\test\checkform.php on line 737

[28-May-2010 13:17:05] PHP Notice:  End of Constructor[0] in F:\WebSites\test\checkform.php on line 659
[28-May-2010 13:17:05] PHP Notice:  POST SUBMIT CATCHED in F:\WebSites\test\checkform.php on line 811
[28-May-2010 13:17:05] PHP Notice:  getStackError[0] in F:\WebSites\test\checkform.php on line 673
En gras, j'ai mis le cntStack qui est le nombre de message inséré dans le Stack... lequel est bien incrémenté en partant de zéro à chaque champs !!!!)
Mais c'est justement le problème, il est raz à chaque champs et non au moment du __construct de Checkfom...

Un p'tit coup de main svp....