Bonjour à tous !

Je viens vers vous pour avoir une réponse.

J'ai un formulaire en ligne, en PHP, et depuis quelques temps je reçois des validations de robots, ce qui est toujours désagréable.


J'aimerais mettre en place un petit "captcha" afin de contrer les validation automatiques, mais je n'aime pas les captcha qu'on voit souvent, avec des lettres tordues, parfois dures à déchiffrer.

Je voulais savoir si pouviez me donner une indication pour intégrer la phrase suivante :"Combien font deux + deux?" et la seule réponse possible serait "quatre".

Voici mon code 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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<?php
// Couleur du texte des champs si erreur saisie utilisateur
$color_font_warn="#FF0000";
// Couleur de fond des champs si erreur saisie utilisateur
$color_form_warn="#FFCC66";
// Ne rien modifier ci-dessous si vous n'êtes pas certain de ce que vous faites !
$list['f_6']=array("Amincissement"," Yoga"," Musculation"," Pilates"," Tonification générale"," Self-Defense"," Tennis"," Squash"," Gym douce");
$list['f_8']=array("Salsa"," Tango"," Rock"," Danse oreintale"," Danse africaine"," Danse classique"," Modern'Jazz"," Country"," Valse"," Danse Africaine");
$list['f_10']=array("Fréquence découverte : 1 heure "," Fréquence Initiation : 3 heures "," Fréquence détermination : + 6 heures");
$list['f_11']=array("Formule Évasion : 3 heures de danse thématique "," Formule Enterrement de vie de célibataire"," Formule Apprendre la valse du mariage ");
$list['f_14']=array("Oui");
if(isset($_POST['submit'])){
    $erreur="";
    // Nettoyage des entrées
    while(list($var,$val)=each($_POST)){
    if(!is_array($val)){
        $$var=strip_tags($val);
    }else{
        while(list($arvar,$arval)=each($val)){
                $$var[$arvar]=strip_tags($arval);
            }
        }
    }
    // Formatage des entrées
    $f_1=trim(ucwords(eregi_replace("[^a-zA-Z0-9éèàäö\ -]", "", $f_1)));
    $f_2=trim(ucwords(eregi_replace("[^a-zA-Z0-9éèàäö\ -]", "", $f_2)));
    $f_3=strip_tags(trim($f_3));
    $f_5=trim(ucwords(eregi_replace("[^a-zA-Z0-9éèàäö\ -]", "", $f_5)));
    $f_7=trim(ucwords(eregi_replace("[^a-zA-Z0-9éèàäö\ -]", "", $f_7)));
    $f_9=trim(ucwords(eregi_replace("[^a-zA-Z0-9éèàäö\ -]", "", $f_9)));
    $f_12=trim(ucwords(eregi_replace("[^a-zA-Z0-9éèàäö\ -]", "", $f_12)));
    // Verification des champs
    if(strlen($f_1)<2){
        $erreur.="<li><span class='txterror'>Le champ &laquo; Nom et Prénom &raquo; est vide ou incomplet.</span>";
        $errf_1=1;
    }
    if(strlen($f_2)<2){
        $erreur.="<li><span class='txterror'>Le champ &laquo; Téléphone &raquo; est vide ou incomplet.</span>";
        $errf_2=1;
    }
    if(strlen($f_3)<2){
        $erreur.="<li><span class='txterror'>Le champ &laquo; Email &raquo; est vide ou incomplet.</span>";
        $errf_3=1;
    }else{
        if(!ereg('^[-!#$%&\'*+\./0-9=?A-Z^_`a-z{|}~]+'.
        '@'.
        '[-!#$%&\'*+\/0-9=?A-Z^_`a-z{|}~]+\.'.
        '[-!#$%&\'*+\./0-9=?A-Z^_`a-z{|}~]+$',
        $f_3)){
            $erreur.="<li><span class='txterror'>La syntaxe de votre adresse e-mail n'est pas correcte.</span>";
            $errf_3=1;
        }
    }
    if(strlen($f_5)<2){
        $erreur.="<li><span class='txterror'>Le champ &laquo; Ville &raquo; est vide ou incomplet.</span>";
        $errf_5=1;
    }
    if(!$f_14){
        $erreur.="<li><span class='txterror'>Le champ &laquo; Je déclare avoir pris connaissance des conditions générales de Vente et de les avoir acceptées. &raquo; requiert au moins une sélection.</span>";
        $errf_14=1;
    }
    if($erreur==""){
        // Création du message
        $titre="Message de votre site";
        $tete="From:Site@Savoir-danser.com\n";
        $corps.="Nom et Prénom : ".$f_1."\n";
        $corps.="Téléphone : ".$f_2."\n";
        $corps.="Email : ".$f_3."\n";
        $corps.="Adresse (rue, digicode, ect) : ".$f_4."\n";
        $corps.="Ville : ".$f_5."\n";
        for($id=0; $id<count($list['f_6']); $id++){
            if($f_6[$id]==1){
                $corps.="Sport désiré (plusieur réponses possibles) : : ".$list['f_6'][$id]."\n";
            }
        }
        $corps.="Autre sport (précisez) : ".$f_7."\n";
        for($id=0; $id<count($list['f_8']); $id++){
            if($f_8[$id]==1){
                $corps.="Danse désirée (plusieurs réponses possibles) : ".$list['f_8'][$id]."\n";
            }
        }
        $corps.="Autre danse (précisez) : ".$f_9."\n";
        $corps.="Fréquence souhaitée : ".$list['f_10'][$f_10]."\n";
        for($id=0; $id<count($list['f_11']); $id++){
            if($f_11[$id]==1){
                $corps.="Formules spéciales : ".$list['f_11'][$id]."\n";
            }
        }
        $corps.="Si cours collectif, indiquez le nombre de personnes : : ".$f_12."\n";
        $corps.="Remarques, suggestions : : ".$f_13."\n";
        for($id=0; $id<count($list['f_14']); $id++){
            if($f_14[$id]==1){
                $corps.="Je déclare avoir pris connaissance des conditions générales de Vente et de les avoir acceptées. : ".$list['f_14'][$id]."\n";
            }
        }
        if(mail("moi@monsite.com", $titre, stripslashes($corps), $tete)){
            $ok_mail="true";
        }else{
            $erreur.="<li><span class='txterror'>Une erreur est survenue lors de l'envoi du message, veuillez refaire une tentative.</span>";
        }
    }
}
?>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 
 
<style type="text/css" media="screen">
<!--
INPUT { color: #000; font-size: 11px; font-family: verdana, Arial, Helvetica, Geneva, Swiss, SunSans-Regular; background-color: #EEEEEE }
SELECT { color: #000; font-size: 11px; font-family: verdana, Arial, Helvetica, Geneva, Swiss, SunSans-Regular; background-color: #EEEEEE }
TEXTAREA { color: #000; font-size: 11px; font-family: verdana, Arial, Helvetica, Geneva, Swiss, SunSans-Regular; background-color: #EEEEEE }
.txterror { color: black; font-size: 11px; font-family: Verdana, Arial, Helvetica, Geneva, Swiss, SunSans-Regular }
.txtform { color: black; font-size: 12px; font-family: Verdana, Arial, Helvetica, Geneva, Swiss, SunSans-Regular }
body {
    background-image: url(/images/linefond.jpg);
}
.Style1 {color: #333333}
.Style2 {color: #333333; font-size: 11px; font-family: Verdana, Arial, Helvetica, Geneva, Swiss, SunSans-Regular; }
.Style3 {color: #333333; font-size: 12px; font-family: Verdana, Arial, Helvetica, Geneva, Swiss, SunSans-Regular; }
.Style4 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: xx-large;
}
.Style5 {
    color: #9D080C;
    font-family: Arial, Helvetica, sans-serif;
}
.Style6 {font-size: 10px}
a:link {
    color: #666666;
}
-->
</style>
 
</head>
 
<body>
 
<? if($ok_mail=="true"){ ?>
    <table width='80%' border='0' cellspacing='1' cellpadding='1' align="center">
        <tr><td><span class='txtform'>Le message ci-dessous nous a bien été transmis, et nous vous en remercions.</span></td></tr>
        <tr><td>&nbsp;</td></tr>
        <tr><td><tt><?echo nl2br(stripslashes($corps));?></tt></td></tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
          <td><p class="txtform">Soyez assur&eacute;s que nous donnerons une suite &agrave; votre demande dans les meilleurs d&eacute;lais.</p>
          <p class="txtform"> </p></td>
        </tr>
    </table>
<? }else{ ?>
<form action='<? echo $PHP_SELF ?>' method='post' name='Form'>
<table width='95%' border='0' align="right" cellpadding='1' cellspacing='1'>
<? if($erreur){ ?>
<tr><td colspan='2' bgcolor='red'><span class='txterror'><font color='white'><b>&nbsp;ERREUR, votre message n'a pas été transmis</b></font></span></td></tr>
 
<tr><td colspan='2'><ul class="Style1"><?echo$erreur?></ul></td></tr><?}?>
<tr>
  <td colspan='2'><div align="left"></td>
</tr>
<tr>
  <td colspan='2'><div align="left"><span class="Style4"><img src="particulier.jpg" alt="cours de danse particulier" width="103" height="34" /><br />
    <img src="images/ligne-tiret.gif" alt="cours de sport a domicile" width="567" height="5" /><br />
    <br />
    FORMULAIRE DE R&Eacute;SERVATION</span></div></td>
</tr>
<tr>
  <td colspan='2'><div align="center"><span class="Style5">ou demande d'informations sans engagement. </span></div></td>
</tr>
<tr><td colspan='2'><div align="center"><span class='Style2'>Les champs marqué d'un * sont obligatoires</span></div></td></tr>
<tr>
  <td height="26" align='right'>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td width='51%' height="26" align='right'><span class='Style3'>Nom et Prénom* :</span></td>
<td width="49%"><input name='f_1' type='text' style='width:200 <?if($errf_1==1){print("; background-color: ".$color_form_warn."; color: ".$color_font_warn);}?>;' value='<?echo stripslashes($f_1);?>' size='24' border='0'></td></tr>
<tr>
  <td width='51%' height="23" align='right'><span class='Style3'>Téléphone* :</span></td>
<td><input name='f_2' type='text' style='width:200 <?if($errf_2==1){print("; background-color: ".$color_form_warn."; color: ".$color_font_warn);}?>;' value='<?echo stripslashes($f_2);?>' size='24' border='0'></td></tr>
<tr><td width='51%' height="25" align='right'><span class='Style3'>Email* :</span></td>
<td><input name='f_3' type='text' style='width:200 <?if($errf_3==1){print("; background-color: ".$color_form_warn."; color: ".$color_font_warn);}?>;' value='<?echo stripslashes($f_3);?>' size='24' border='0'></td></tr>
<tr><td align='right' width='51%' VALIGN=TOP><span class='Style3'>Adresse (rue, digicode, ect) :</span></td>
  <td><span style="color: #333333">
    <textarea style='width:360 <?if($errf_4==1){print("; background-color: ".$color_form_warn."; color: ".$color_font_warn);}?>;' name='f_4' rows='6' cols='40'><?echo$f_4?></textarea>
  </span></td>
</tr>
<tr><td width='51%' height="23" align='right'><span class='Style3'>Ville* :</span></td><td><input name='f_5' type='text' style='width:200 <?if($errf_5==1){print("; background-color: ".$color_form_warn."; color: ".$color_font_warn);}?>;' value='<?echo stripslashes($f_5);?>' size='24' border='0'></td></tr>
<tr>
  <td height="32" align='right'>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td width='51%' height="179" align='right' VALIGN=TOP><span class='Style3'>Sport  désiré <span class="Style6">(plusieurs souhaits possibles)</span>  :</span></td><td>
<table border='0' cellspacing='0' cellpadding='0'>
<? for($id=0;$id<count($list['f_6']);$id++){
if($f_6[$id]==1){$ct="checked";}
print("<tr><td><input ".$ct." type='checkbox' name='f_6[$id]' value='1' border='0'></td><td><span class='txtform'>".$list[f_6][$id]."</span></td></tr>");
unset($ct);
}?>
</table>
</td></tr>
<tr><td align='right' width='51%'><span class='Style3'>Autre sport (précisez) :</span></td><td><input name='f_7' type='text' style='width:200 <?if($errf_7==1){print("; background-color: ".$color_form_warn."; color: ".$color_font_warn);}?>;' value='<?echo stripslashes($f_7);?>' size='24' border='0'></td></tr>
<tr>
  <td align='right'>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td align='right' width='51%' VALIGN=TOP><span class='Style3'>Danse désirée <span class="Style6">(plusieurs souhaits possibles)</span> :</span></td><td>
<table border='0' cellspacing='0' cellpadding='0'>
<? for($id=0;$id<count($list['f_8']);$id++){
if($f_8[$id]==1){$ct="checked";}
print("<tr><td><input ".$ct." type='checkbox' name='f_8[$id]' value='1' border='0'></td><td><span class='txtform'>".$list[f_8][$id]."</span></td></tr>");
unset($ct);
}?>
</table>
</td></tr>
<tr><td align='right' width='51%'><span class='Style3'>Autre danse (précisez) :</span></td><td><input name='f_9' type='text' style='width:200 <?if($errf_9==1){print("; background-color: ".$color_form_warn."; color: ".$color_font_warn);}?>;' value='<?echo stripslashes($f_9);?>' size='24' border='0'></td></tr>
<tr>
  <td align='right'>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td align='right' width='51%' VALIGN=TOP><span class='Style3'>Fréquence souhaitée :</span></td><td>
<table border='0' cellspacing='0' cellpadding='0'>
<? for($id=0;$id<count($list['f_10']);$id++){
if($id==$f_10){$ct="checked";}
print("<tr><td><input ".$ct." type='radio' name='f_10' value=".$id." border='0'></td><td><span class='txtform'>".$list[f_10][$id]."</span></td></tr>");
unset($ct);
}?>
</table>
</td></tr>
<tr>
  <td align='right' VALIGN=TOP>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr><td align='right' width='51%' VALIGN=TOP><span class='Style3'>Formules spéciales :</span></td><td>
<table border='0' cellspacing='0' cellpadding='0'>
<? for($id=0;$id<count($list['f_11']);$id++){
if($f_11[$id]==1){$ct="checked";}
print("<tr><td><input ".$ct." type='checkbox' name='f_11[$id]' value='1' border='0'></td><td><span class='txtform'>".$list[f_11][$id]."</span></td></tr>");
unset($ct);
}?>
</table>
</td></tr>
<tr>
  <td align='right' width='51%'><span class='Style3'>Si cours collectif, indiquez le nombre de personnes :</span></td><td><input name='f_12' type='text' style='width:200 <?if($errf_12==1){print("; background-color: ".$color_form_warn."; color: ".$color_font_warn);}?>;' value='<?echo stripslashes($f_12);?>' size='24' border='0'></td></tr>
<tr>
  <td height="21" align='right'>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td width='51%' height="88" align='right' VALIGN=TOP><p class="Style3"><strong>Disponibilités</strong> durant lesquelles <br />
    vous souhaiteriez prendre vos cours, ou commentaires :</p>
    <p class="Style3 Style6">(Par exemple &quot;Tous les jeudi matin&quot; ou bien &quot;Tous les soirs vers 19 heures&quot;, ect)</p></td>
  <td><span style="color: #333333">
  <textarea style='width:360 <?if($errf_13==1){print("; background-color: ".$color_form_warn."; color: ".$color_font_warn);}?>;' name='f_13' rows='6' cols='40'><?echo$f_13?></textarea>
</span></td></tr>
<tr>
  <td align='right'>&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td align='right' width='51%'><span class='Style3'>Je déclare être majeur et avoir lu et <br />
    accepté
  les conditions générales de Vente</a> .*</span></td>
  <td>
<table border='0' cellspacing='0' cellpadding='0'>
<? for($id=0;$id<count($list['f_14']);$id++){
if($f_14[$id]==1){$ct="checked";}
print("<tr><td><input ".$ct." type='checkbox' name='f_14[$id]' value='1' border='0'></td><td><span class='txtform'>".$list[f_14][$id]."</span></td></tr>");
unset($ct);
}?>
</table>
</td></tr>
<tr>
  <td align='right'></td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td align='right'>&nbsp;</td>
  <td><input name='submit' type='submit' value='Envoyer' border='0' /></td>
</tr>
<tr><td colspan="2" align='right'><span class="Style1">
    </tr>
  </table>
</td></tr>
</table>
</form>
<? } ?>
 
</body>
</html>
Merci de vos lumières et à bientot !

David