Bonjour,
J'ai un souci avec une classe Date que j'écris pour intégration future dans un script de validation d'une <form>
J'ai un HTML qui appelle cette classe et que voici:
Voici la classe Date:
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 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- ============================================================================================================================ --> <!-- === Style === --> <!-- ============================================================================================================================ --> <link href="../css/jecrapahute.css" rel="stylesheet" type="text/css"/> <!-- ============================================================================================================================ --> <title>Class Date Test</title> </head> <?php // =============================================================================================================================== // require_once $_SERVER['DOCUMENT_ROOT'] . "/class/equate.php"; require_once $_SERVER['DOCUMENT_ROOT'] . "/class/date.php"; // =============================================================================================================================== // /** * Définition ds champs * ==================== */ require_once $_SERVER['DOCUMENT_ROOT'] . "/config/constants.php"; require_once $_SERVER['DOCUMENT_ROOT'] . "/config/newFuncts.php"; $birthdate = new Date ( "naissance" , MUST , "Date de naissance" , TODAY ) ; $birthdate->setDefault() ; $birthdate->debug() ; /** * Interception du bouton SUBMIT * ============================= */ if (isset($_POST['Submit'])) {// if ($this->debug) user_error("POST SUBMIT CATCHED" , E_USER_NOTICE) ; if ($birthdate->isFieldValid()) { # Formulaire valide # ================= $result = $birthdate->getFieldValue() ; 38 ==> $msg = "Date Valide['$result'] ! " ; user_error("Date Valide[".$birthdate->getFieldValue()."]", E_USER_NOTICE) ; } else { # Formulaire invalide # =================== $msg = "Date Invalide ! " ; user_error("Date Invalide", E_USER_NOTICE) ; } } /** * HTML FORM DEFINITION * */ require_once $_SERVER['DOCUMENT_ROOT'] . "/config/newFuncts.php"; ?> <body> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" name="date" id="date"> <table width="818" border="1"> <tr> <td width="100"> </td> <td width="400"><div align="center">Test de la classe <em>DATE</em></div></td> <td width="100"> </td> </tr> <tr> <td> </td> <td><?php $birthdate->display() ?></td> <td> </td> </tr> <tr> <td colspan="3"><hr /></td> </tr> <tr> <td> </td> <td width="400"><label> 77 ==> <input name="msg" type="text" id="msg" value="<?php if (isset($_POST['msg'])) echo $_POST['msg'] ?>" size="50" maxlength="50" /> </label></td> <td><div align="center"> <input type="submit" name="Submit" id="Submit" value="Submit" /> </div></td> </tr> </table> <hr /> </form> </body> </html>
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201 <?php /** * DATE[validation] constructor * */ class Date // extends Form { private $defYY = NULL , $YY = NULL ; private $defMM = NULL , $MM = NULL ; private $defDD = NULL , $DD = NULL ; private $month = array ( "01" => "Jan" , "02" => "Fev" , "03" => "Mar" , "04" => "Avr" , "05" => "Mai" , "06" => "Juin" , "07" => "Juil" , "08" => "Aou" , "09" => "Sep" , "10" => "Oct" , "11" => "Nov" , "12" => "Dec" ) ; function __construct($name, $must, $legend, $default, $debug=false) { $this->name = $name ; $this->must = $must ; $this->legend = $legend ; $this->value = (isset( $_POST["$this->name"] ) ) ? trim($_POST["$this->name"]) : NULL ; $this->debug = $debug ; if (isset($default)) switch($default) { case TODAY : $this->date = date("Ymd") ; break ; default : user_error("Invalid Date default", E_USER_ERROR) ; break ; } else $this->date = date("Ymd") ; // ================================================================== 20101109 /* $this->YY = $this->fill(substr($this->date,0,4),4) ; // ======== $this->MM = $this->fill(substr($this->date,4,2),2) ; // 01234567 $this->DD = $this->fill(substr($this->date,6,2),2) ; // YYYYMMDD if ($this->debug) var_dump("===> CONSTRUCT DATE =>: ",$this->date) ; */ } function __destruct() { } function execute() { } /** * validate * ======== */ function validate() { return( checkdate($this->fill($this->MM,2), $this->fill($this->DD,2), $this->fill($this->YY,4) ) ? OK : ERRDATE) ; } /** * debug * ===== */ function debug() { var_dump($this->defYY , $this->YY , $this->defMM , $this->MM , $this->defDD , $this->DD ) ; } /** * setDefault * ========== */ function setDefault($defYY=NULL, $defMM=NULL, $defDD=NULL) { $this->defYY = ($defYY != NULL) ? $defYY : date("Y") ; $this->defMM = ($defMM != NULL) ? $defMM : date("m") ; $this->defDD = ($defDD != NULL) ? $defDD : date("d") ; } /** * pickup * ======= * */ function pickup($start,$end,$len,$frmfld,$default) { echo "<select name='" . $frmfld . "' id='" . $frmfld . "'>\n"; for ($i = $start ; $i <= $end ; $i++) { $d = $this->fill($i,$len) ; if (strcmp($default,$d) == 0) echo ' <option value="' . $d . '" selected">' . $d. "</option>\n" ; else echo ' <option value="' . $d . '">' . $d . "</option>\n" ; } echo "</select>\n" ; } /** * select * ======= * */ function select($valarray,$frmfld,$default) { echo "<select name='" . $frmfld . "' id='" . $frmfld . "'>\n"; foreach ($valarray as $key => $value) { if (strcmp($default,$key) == 0) echo ' <option value="' . $key . '" selected">' . $value . "</option>\n" ; else echo ' <option value="' . $key . '">' . $value . "</option>\n" ; } echo "</select>\n" ; } /** * fill * ==== */ function fill($str,$len) { //user_error("==> fill[".$str."] <= [".strlen($str)."] < [".$len."]",E_USER_NOTICE) ; for ($i = 0 ; strlen($str) < $len ; $i++) { //user_error("+" , E_USER_NOTICE) ; $str = "0" . $str ; } //user_error("==> fill[".$str."] - [".$len."]",E_USER_NOTICE) ; return($str) ; } /** * display * ======= * */ function display() { $this->DD = (isset($_POST["DD"])) ? $_POST["DD"] : date("d") ; $this->MM = (isset($_POST["MM"])) ? $_POST["MM"] : date("m") ; // format interne $this->YY = (isset($_POST["YY"])) ? $_POST["YY"] : date("Y") ; echo "<fieldset><legend class='form_lbl'>" ; echo $this->legend ; echo "</legend>" ; echo '<span class="form_fld fieldset">' ; $this->pickup(1,31,2, $name="DD",$default=$this->DD) ; echo '</span>' ; echo '<span class="form_bkg fieldset">' ; echo "-" ; echo '</span>' ; echo '<span class="form_fld fieldset">' ; $this->select($this->month, $name="MM",$default=$this->MM) ; //array_search($this->MM, $this->month)) ; echo '</span>' ; echo '<span class="form_bkg">' ; echo "-" ; echo '</span>' ; echo '<span class="form_fld">' ; $this->pickup(1920,2020,4, $name="YY",$default=$this->YY) ; echo '</span>' ; echo "</fieldset>" ; $this->YY = (isset($_POST["YY"])) ? $_POST["YY"] : date("Y") ; $this->MM = (isset($_POST["MM"])) ? $_POST["MM"] : date("m") ; // format interne $this->DD = (isset($_POST["DD"])) ? $_POST["DD"] : date("d") ; $this->value = sprintf("%04s%02s%02s",$this->YY, $this->MM, $this->DD) ; 155 => user_error("display(2) => Date de naissance[".$this->value."]", E_USER_NOTICE) ; } /** * getFieldName * ============ * */ function getFieldName() { return($this->name) ; } /** * getFieldLegend * ============== * */ function getFieldLegend() { return($this->legend) ; } /** * getFieldValue * ============= * */ function getFieldValue() { $date = sprintf("%04s%02s%02s",$this->YY, $this->MM, $this->DD) ; user_error("===>getFieldValue[".$date."]" . $this->YY . $this->MM . $this->DD, E_USER_NOTICE) ; return( $date ) ; } /** * isFieldValid * ============ * */ function isFieldValid() { $rc = $this->validate() ; if ($rc == OK) $msg = "Date Valid" ; else $msg = "Date INVALID" ; return( $rc ) ; } } /** ========================================================================================================================================================= * End Of Class: DATE * ======================================================================================================================================================== */ ?>Et le log PHP
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 La fonction display ligne 155 du script affiche bien à l'écran: string(4) "2010" NULL string(2) "12" NULL string(2) "15" NULL
Mon problème réside dans le fait que j'affiche bien la date du jour (même si je l'ai changée....) donc, le POST est bien intercepté... A L'INITIALISATION...
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 [15-Dec-2010 15:24:09] PHP Notice: POST SUBMIT CATCHED in F:\WebSites\date\index.php on line 33 [15-Dec-2010 15:24:09] PHP Stack trace: [15-Dec-2010 15:24:09] PHP 1. {main}() F:\WebSites\date\index.php:0 [15-Dec-2010 15:24:09] PHP 2. user_error() F:\WebSites\date\index.php:33 [15-Dec-2010 15:24:09] PHP Notice: ===>getFieldValue[00000000] in F:\WebSites\date\class\date.php on line 180 [15-Dec-2010 15:24:09] PHP Stack trace: [15-Dec-2010 15:24:09] PHP 1. {main}() F:\WebSites\date\index.php:0 [15-Dec-2010 15:24:09] PHP 2. Date->getFieldValue() F:\WebSites\date\index.php:37 [15-Dec-2010 15:24:09] PHP 3. user_error() F:\WebSites\date\class\date.php:180 [15-Dec-2010 15:24:09] PHP Notice: ===>getFieldValue[00000000] in F:\WebSites\date\class\date.php on line 180 [15-Dec-2010 15:24:09] PHP Stack trace: [15-Dec-2010 15:24:09] PHP 1. {main}() F:\WebSites\date\index.php:0 [15-Dec-2010 15:24:09] PHP 2. Date->getFieldValue() F:\WebSites\date\index.php:39 [15-Dec-2010 15:24:09] PHP 3. user_error() F:\WebSites\date\class\date.php:180 [15-Dec-2010 15:24:09] PHP Notice: Date Valide[00000000] in F:\WebSites\date\index.php on line 39 [15-Dec-2010 15:24:09] PHP Stack trace: [15-Dec-2010 15:24:09] PHP 1. {main}() F:\WebSites\date\index.php:0 [15-Dec-2010 15:24:09] PHP 2. user_error() F:\WebSites\date\index.php:39 [15-Dec-2010 15:24:09] PHP Notice: display(2) => Date de naissance[20101215] in F:\WebSites\date\class\date.php on line 155 [15-Dec-2010 15:24:09] PHP Stack trace: [15-Dec-2010 15:24:09] PHP 1. {main}() F:\WebSites\date\index.php:0 [15-Dec-2010 15:24:09] PHP 2. Date->display() F:\WebSites\date\index.php:68 [15-Dec-2010 15:24:09] PHP 3. user_error() F:\WebSites\date\class\date.php:155
Mais le coding (en gras) n'est pas exécuté (ou semble pas... j'ai tjs un doute)!
J'ai bien:
dans le log mais pas la logique TRUE/FALSE qui suit et qui devrait m’afficher un msg à la ligne 77 de index.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part user_error("POST SUBMIT CATCHED" , E_USER_NOTICE) ;
Même si cela semble correct, je ne suis pas habitué à la config PHP depuis que j'ai installé PEAR... je mets cette config en pièce attachée.
Merci pour votre coup de main.
Code : Sélectionner tout - Visualiser dans une fenêtre à part Ce qui est certain est que je n'affiche pas la variable $msg dans la zone prévue à cet effet dans ma forme....voir ligne 38 de index.php![]()
Partager