Bonjour,

J'ai un formulaire avec des champs obligatoire dont des boutons d'options.

J'ai une option obligatoire (Choix entrre DEVIS & COMMANDE)

Comment mettre un test dessus?

Voilà mon code..

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
<?php 
 
$default = array(); 
$default['txtNum'] = isset($_POST['txtNum'])?$_POST['txtNum']:'';
$default['txtSociete'] = isset($_POST['txtSociete'])?$_POST['txtSociete']:'';
....................
......................
............................
 
if (isset($_POST['cmdEnvoyer'])) { 
    require_once('TestFormulaire.php'); 
 
    // Register the subclasses to use 
    $v['er'] = new ValidateRequired('Nom', $_POST['txtNom']); 
    $v['s']  = new ValidateRequired('Prénom', $_POST['txtPrenom']); 
	$v['t']  = new ValidateRequired('Adresse', $_POST['txtAdresse']);
	$v['u']  = new ValidateRequired('Code Postal', $_POST['txtCP']);
	$v['v']  = new ValidateRequired('Ville', $_POST['txtVille']);
	$v['w']  = new ValidateRequired('Téléphone', $_POST['txtTelephone']);
	$v['x']  = new ValidateRequired('N° de série', $_POST['txtNumSerie']);
	$v['y']  = new ValidateRequired('1ère mise en circulation', $_POST['txtMiseEnCircu']);
    $v['e']  = new ValidateEmail($_POST['txtMail']); 
 
    $errorMsg = ''; 
    // Perform each validation 
    foreach($v as $validator) { 
        if (!$validator->isValid()) { 
            while ($error=$validator->getError()) { 
                $errorMsg.="<li>".$error."</li>\n"; 
            } 
        } 
    } 
    if ($errorMsg != '') { 
        print ("<div style='color:red'>Les erreurs suivantes se sont produites:\n<ul>".$errorMsg."</ul></div>"); 
    } else { 
        $Num = $_POST['txtNum']; 
		$Societe = $_POST['txtSociete'];
		$Nom = $_POST['txtNom']; 
		$Prenom = $_POST['txtPrenom'];
		$Mail = $_POST['txtMail']; 
		$Adresse=$_POST['txtAdresse'];
		$CP=$_POST['txtCP'];
		$Ville=$_POST['txtVille'];
		$Telephone=$_POST['txtTelephone']; 
 
		if($_POST['cmbNumSerie']=="WDB") $TypeSerie ="WDB";
		elseif($_POST['cmbNumSerie']=="WDC") $TypeSerie ="WDC";
		elseif($_POST['cmbNumSerie']=="VSA") $TypeSerie ="VSA";
		else $TypeSerie ="WDF";
		$NumSerie=$_POST['txtNumSerie'];
		$MiseEnCircu=$_POST['txtMiseEnCircu'];
 
		$Des1=$_POST['txtDes1'];
		if($_POST['cmbRef1']=="") $TypeRef1 ="";
		elseif($_POST['cmbRef1']=="Mercedes") $TypeRef1 ="Mercedes";
		else $TypeRef1="---";
		$Ref1=$_POST['txtRef1'];
		$Qte1=$_POST['txtQte1'];
 
		$Des2=$_POST['txtDes2'];
		if($_POST['cmbRef2']=="") $TypeRef2 ="";
		elseif($_POST['cmbRef2']=="Mercedes") $TypeRef2 ="Mercedes";
		else $TypeRef2="---";
		$Ref2=$_POST['txtRef2'];
		$Qte2=$_POST['txtQte2'];
 
		$Des3=$_POST['txtDes3'];
		if($_POST['cmbRef3']=="") $TypeRef3 ="";
		elseif($_POST['cmbRef3']=="Mercedes") $TypeRef3 ="Mercedes";
		else $TypeRef3="---";
		$Ref3=$_POST['txtRef3'];
		$Qte3=$_POST['txtQte3'];
 
		$Commentaire=$_POST['txtCommentaire'];
 
 
		$Destinataire = "nicolas.@.fr" ; 
 
		if($_POST['optChoix']=="Devis") $Sujet =" - Devis";
		else $Sujet="- Commande";
 
		$Message = "Client n° : $Num \n 
		Société : $Societe \n
		Nom : $Nom \n
		Prénom : $Prenom \n
		Adresse : $Adresse \n
		Code Postal : $CP \n
		Ville : $Ville \n
		Téléphone : $Telephone \n \n
		Véhicule concerné : \n
		N° de série : $TypeSerie $NumSerie \n
		Mis en circualtion : $MiseEnCircu \n \n
		Détail de la demande : \n
		Désignation 1 : $Des1 \n
		Référence 1 : $TypeRef1 $Ref1 \n
		Le client en souhaite $Qte1 \n \n
		Désignation 2 : $Des2 \n
		Référence 2 : $TypeRef2 $Ref2 \n
		Le client en souhaite $Qte2 \n \n
		Désignation 3 : $Des3 \n
		Référence 3 : $TypeRef3 $Ref3 \n
		Le client en souhaite $Qte3 \n \n \n
		Commentaire du client : $Commentaire ";
		$Entetes = "From: $Mail " ; 
		mail($Destinataire, $Sujet, $Message, $Entetes); 
		print ('<h2>Demande envoyée avec succès !</h2>'); 
    } 
} 
?> 
 
 
  <form name="Formulaire_Mail" action="<?php echo ($_SERVER['PHP_SELF']); ?>" method="post"> 
<table width="95%" height="921" id="tabGeneral"> 
  <tr> 
    <td height="72" colspan="4" class="GrosTitredePageGris"><div align="left" class="GrosTitredePageRouge">Nos Services en ligne </div></td> 
  </tr> 
 
  <tr>
    <td height="40" align="center" valign="top">&nbsp;</td>
    <td colspan="2" align="center" valign="top"><div align="left">Les champs marqu&eacute;s d'une<span class="Style5"> *</span> sont obligatoire </div></td>
    </tr>
  <tr> 
    <td width="82" height="40" align="center" valign="top"> 
    <p align="left" class="InfosSites">&nbsp;</p>    </td> 
 
    <td width="299" align="center" valign="top"> 
      <label> 
        <div align="left"> 
          <input type="radio" name="optChoix" value="Devis" /> 
          <span class="InfosSites Style4">Devis</span></div> 
      </label>    </td> 
    <td width="559" align="center" valign="top"> 
      <label> 
        <div align="left"> 
          <input type="radio" name="optChoix" value="Commande" /> 
          <span class="InfosSites Style4">Commande</span><span class="Style1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*</span></div> 
        </label>   </td> 
................
..................................
</table> 
</form>
TestFormualire
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
202
203
<?php 
/** 
 *  Validator superclass for form validation 
 */ 
class Validator { 
    /** 
    * Private 
    * $errorMsg stores error messages if not valid 
    */ 
    var $errorMsg; 
 
    //! A constructor. 
    /** 
    * Constucts a new Validator object 
    */ 
    function Validator () { 
        $this->errorMsg=array(); 
        $this->validate(); 
    } 
 
    //! A manipulator 
    /** 
    * @return void 
    */ 
    function validate() { 
        // Superclass method does nothing 
    } 
 
    //! A manipulator 
    /** 
    * Adds an error message to the array 
    * @return void 
    */ 
    function setError ($msg) { 
        $this->errorMsg[]=$msg; 
    } 
 
    //! An accessor 
    /** 
    * Returns true is string valid, false if not 
    * @return boolean 
    */ 
    function isValid () { 
        if ( isset ($this->errorMsg) ) { 
            return false; 
        } else { 
            return true; 
        } 
    } 
 
    //! An accessor 
    /** 
    * Num'Pops the last error message off the array 
    * @return string 
    */ 
    function getError () { 
        return array_pop($this->errorMsg); 
    } 
} 
 
/** 
 *  ValidatorUser subclass of Validator 
 *  Validates a username 
 */ 
class ValidateUser extends Validator { 
    /** 
    * Private 
    * $user the username to validate 
    */ 
    var $user; 
 
    //! A constructor. 
    /** 
    * Constucts a new ValidateUser object 
    * @param $user the string to validate 
    */ 
    function ValidateUser ($user) { 
        $this->user=$user; 
        Validator::Validator(); 
    } 
 
    //! A manipulator 
    /** 
    * Validates a username 
    * @return void 
    */ 
    function validate() { 
        if (!preg_match('/^[a-zA-Z0-9_]+$/',$this->user )) { 
            $this->setError('Username contains invalid characters'); 
        } 
        if (strlen($this->user) < 6 ) { 
            $this->setError('Username is too short'); 
        } 
        if (strlen($this->user) > 20 ) { 
            $this->setError('Username is too long'); 
        } 
    } 
} 
 
/** 
 *  ValidatorPassword subclass of Validator 
 *  Validates a password 
 */ 
class ValidatePassword extends Validator { 
    /** 
    * Private 
    * $pass the password to validate 
    */ 
    var $pass; 
    /** 
    * Private 
    * $conf to confirm the passwords match 
    */ 
    var $conf; 
 
    //! A constructor. 
    /** 
    * Constucts a new ValidatePassword object subclass or Validator 
    * @param $pass the string to validate 
    * @param $conf to compare with $pass for confirmation 
    */ 
    function ValidatePassword ($pass,$conf) { 
        $this->pass=$pass; 
        $this->conf=$conf; 
        Validator::Validator(); 
    } 
 
    //! A manipulator 
    /** 
    * Validates a password 
    * @return void 
    */ 
    function validate() { 
        if ($this->pass!=$this->conf) { 
            $this->setError('Passwords do not match'); 
        } 
        if (!preg_match('/^[a-zA-Z0-9_]+$/',$this->pass )) { 
            $this->setError('Password contains invalid characters'); 
        } 
        if (strlen($this->pass) < 6 ) { 
            $this->setError('Password is too short'); 
        } 
        if (strlen($this->pass) > 20 ) { 
            $this->setError('Password is too long'); 
        } 
    } 
} 
 
/** 
 *  ValidatorEmail subclass of Validator 
 *  Validates an email address 
 */ 
class ValidateEmail extends Validator { 
    /** 
    * Private 
    * $email the email address to validate 
    */ 
    var $email; 
 
    //! A constructor. 
    /** 
    * Constucts a new ValidateEmail object subclass or Validator 
    * @param $email the string to validate 
    */ 
    function ValidateEmail ($email){ 
        $this->email=$email; 
        Validator::Validator(); 
    } 
 
    //! A manipulator 
    /** 
    * Validates an email address 
    * @return void 
    */ 
    function validate() { 
        $pattern= 
    "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/"; 
        if(!preg_match($pattern,$this->email)){ 
            $this->setError('Adresse E-Mail invalide'); 
        } 
        if (strlen($this->email)>100){ 
            $this->setError('Addresse E-Mail trop longue'); 
        } 
    } 
} 
 
class ValidateRequired extends Validator { 
    var $name; 
    var $value; 
 
    function ValidateRequired ($name, $value) { 
        $this->name=$name; 
        $this->value=$value; 
        Validator::Validator(); 
    } 
 
    function validate() { 
        if (trim($this->value) == '' ) { 
            $this->setError($this->name.' doit être renseigné !'); 
        } 
    } 
} 
?>

MERCI