IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Class et formulaire [PHP 5.3]


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de ETVigan
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Avril 2010
    Messages
    660
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2010
    Messages : 660
    Par défaut Class et formulaire
    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....

  2. #2
    Membre Expert
    Avatar de ThomasR
    Homme Profil pro
    Directeur technique
    Inscrit en
    Décembre 2007
    Messages
    2 230
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Directeur technique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Décembre 2007
    Messages : 2 230
    Par défaut
    Bonjour,

    Suffit de rendre statique ta variable $cntStack, sinon elle est évidemment propre à chaque instance.

  3. #3
    Membre éclairé Avatar de ETVigan
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Avril 2010
    Messages
    660
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2010
    Messages : 660
    Par défaut Formulaire & class
    Desolé Thomas,

    J'ai déjà essayé....
    Je viens de refaire la modif pour te montrer et tu auras droit à une erreur dans le log php queje ne comprends pas

    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
    [28-May-2010 14:59:59] PHP Notice:  POST SUBMIT CATCHED in F:\WebSites\test\checkform.php on line 795
    [28-May-2010 14:59:59] PHP Notice:  getStackError[0] in F:\WebSites\test\checkform.php on line 657
    [28-May-2010 15:00:46] PHP Notice:  Undefined property: Checkform::$cntStack in F:\WebSites\test\checkform.php on line 653
    [28-May-2010 15:00:46] PHP Notice:  Start of Constructor[] in F:\WebSites\test\checkform.php on line 628
    [28-May-2010 15:00:46] PHP Notice:  emptyStack[0] in F:\WebSites\test\checkform.php on line 676
    [28-May-2010 15:00:46] PHP Notice:  Start of Validation ==> cntStack[0] in F:\WebSites\test\checkform.php on line 712
    [28-May-2010 15:00:46] PHP Notice:  Start Validating field[0]  cntStack[0] in F:\WebSites\test\checkform.php on line 717
    [28-May-2010 15:00:46] 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 669
    [28-May-2010 15:00:46] PHP Notice:  printStack[0] in F:\WebSites\test\checkform.php on line 682
    [28-May-2010 15:00:46] PHP Notice:  End   Validating field[0]  cntStack[0] in F:\WebSites\test\checkform.php on line 721
    [28-May-2010 15:00:46] PHP Notice:  Start Validating field[1]  cntStack[0] in F:\WebSites\test\checkform.php on line 717
    [28-May-2010 15:00:46] 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 669
    [28-May-2010 15:00:46] PHP Notice:  printStack[0] in F:\WebSites\test\checkform.php on line 682
    [28-May-2010 15:00:46] PHP Notice:  End   Validating field[1]  cntStack[0] in F:\WebSites\test\checkform.php on line 721
    [28-May-2010 15:00:46] PHP Notice:  Start Validating field[2]  cntStack[0] in F:\WebSites\test\checkform.php on line 717
    [28-May-2010 15:00:46] PHP Notice:  +++++++ Stacking msg[1][Le champ[numero] doit avoir une longueur comprise entre 3 et 5] in F:\WebSites\test\checkform.php on line 669
    [28-May-2010 15:00:46] PHP Notice:  printStack[0] in F:\WebSites\test\checkform.php on line 682
    [28-May-2010 15:00:46] PHP Notice:  End   Validating field[2]  cntStack[0] in F:\WebSites\test\checkform.php on line 721
    [28-May-2010 15:00:46] PHP Notice:  End of Constructor[0] in F:\WebSites\test\checkform.php on line 643
    [28-May-2010 15:00:46] PHP Notice:  POST SUBMIT CATCHED in F:\WebSites\test\checkform.php on line 795
    [28-May-2010 15:00:46] PHP Notice:  getStackError[0] in F:\WebSites\test\checkform.php on line 657
    Voci la classe ou un extrait....

    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
        	class Checkform
    		{	protected $stackMsg = array();
    653 =>		static $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()
    ICI====>	{	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) ;
    			}

    Nous sommes 3 à chercher depuis 2 jours et pas encore trouv"

    Seras-tu le gagnant ?


    SORRY je me suis trompé, ce n'est pas à la déclaration que le message est sortit mais bien au return($this->cntStack), dont à l'utlisation de ce dernier....

  4. #4
    Membre Expert
    Avatar de ThomasR
    Homme Profil pro
    Directeur technique
    Inscrit en
    Décembre 2007
    Messages
    2 230
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Directeur technique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Décembre 2007
    Messages : 2 230
    Par défaut
    3 personnes pour si peu ?

    Pour appeler un membre statique il ne faut pas faire référence à l'instance mais à la definition de la classe.

    Je ne peux que te conseiller de lire : http://fr.php.net/manual/fr/language.oop5.static.php

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    CheckForm::$cntStack++;
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    function getCntStack(){
        return self::$cntStack;
    }
    edit : aussi, passes ta variable en public et non protected pour pouvoir la valoriser depuis l'exterieur de ta classe et des classes héritées.

  5. #5
    Membre éclairé Avatar de ETVigan
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Avril 2010
    Messages
    660
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2010
    Messages : 660
    Par défaut Privatr ptoperty
    J'allais te pazser d'autres infos, je vais essayer ton idée....

  6. #6
    Membre éclairé Avatar de ETVigan
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Avril 2010
    Messages
    660
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2010
    Messages : 660
    Par défaut Private
    Cela semble fonctionner... j'affiche le nbre d'entrée dans le stack mais pas encore son contenu... c déjoà ça !

    Mais serait content et convaincu quand le contenu sera afficher

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [AC-2007] Mise en oeuvre des modules de classe de formulaire
    Par Triton972 dans le forum IHM
    Réponses: 1
    Dernier message: 26/01/2012, 21h25
  2. Classes et Formulaire
    Par wattaroo dans le forum Langage
    Réponses: 5
    Dernier message: 01/10/2010, 18h56
  3. Où placer les classes de formulaires ?
    Par littleman dans le forum Zend_Form
    Réponses: 5
    Dernier message: 12/09/2008, 14h09
  4. [Vb.net]_Héritage de classe sur formulaire
    Par Gdal dans le forum VB.NET
    Réponses: 3
    Dernier message: 26/03/2007, 20h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo