Bonjour,

Apres un enorme effort, me voila je fais mon premier code Ajax + jQuery de verification des champs d'un formulaire, je voudrais savoir pour en cliquant sur le bouton submit, le formulaire n'envois pas les erreurs en cas de return false:

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
<html dir="rtl">
<head>
<style type="text/css">
#name, #username, #email {
        border-color: #FF0000;
        border-style: solid;
        border-width: 1px;
        border-collapse: collapse;
        -moz-border-radius: 5px;
}
 
#label01 {
        width: 100px;
        display:block;
        float: right;
}
 
.frm_fields {
        padding: 5px;
}
 
input:focus {
      background: #fc9fff;  
}
 
.CurFocus {
background: #fdecb2;
width: 800px;
}
</style>
 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
<script src="jquery.js" type="text/javascript"></script>
 
<script type="text/javascript">
$(document).ready(function(){
 
$("#frm_login :text").focus(function(){ // quand on met la souris au input de la form frm_login
 
        $(this).parent().addClass('CurFocus'); // on ajoute le CurFocus a frm_fields afin de combiner les 2 class
        $(this).parent().find('.info').html('&nbsp;&nbsp;<img src="info.png" width="20" height="20" align="absmiddle"> Message ici'); // on cherche info afin d'ajouter le code HTML
        $(this).parent().find('.eMsg').html(''); // on ecrase le message d'erreur
        $(this).parent().find('.sMsg').html(''); // on ecrase le message de success
        $(this).parent().find('.sAvailable').html(''); // on ecrase le message de success de l'availability
 
 
 
                                        }).blur(function(){ // quand on met la souris au input de la form frm_login
        $(this).parent().removeClass('CurFocus'); // on ajoute le CurFocus a frm_fields afin de combiner les 2 class
        $(this).parent().find('.info').html(''); // on cherche info afin de l'ecraser et la vider
 
 
 });
 
 
        // on determine des variables pour les inputs
        var frm_login = $("#frm_login");
        var name = $("#name");
        var username = $("#username");
        var email = $("#email");
 
 
        // on procede a la verification des champs
        // Nom
        function check_name () {
 
                if (name.val().length < 5)
                {
                        $(this).parent().find('.eMsg').html('<img src="error.png" width="20" height="20" align="absmiddle"> Le nom comporte moins de 5 caracteres!');
                $(this).parent().find('#name').css(
                        "border-color", "#FF0000",
                        "border-width", "1px"
                          );
 
                        return false;
                }
                else
                {      
                        $(this).parent().find('.sMsg').html('<img src="success.png" width="20" height="20" align="absmiddle">');
                $(this).parent().find('#name').css(
                        "border-color", "#badfac",
                        "border-width", "1px"
                          );
                        return true;
                }
        }
 
 
 
                // Username
        function check_username () {
 
                if (username.val().length < 5)
                {
                        $(this).parent().find('.eMsg').html('<img src="error.png" width="20" height="20" align="absmiddle"> Le pseudo comporte moins de 5 caracteres!');
                $(this).parent().find('#username').css(
                        "border-color", "#FF0000",
                        "border-width", "1px"
                          );
 
                        return false;
                }
                else
                {
                $(".sAvailable").html('<img src="loading.gif" width="20" height="20" align="absmiddle"> Checking availability');       
 
                        // on doit verifier la valdite du pseudo
                        //Récupération des valeurs du formulaires
                var name_val            = $("#name").val();
                var username_val        = $("#username").val();
                var dataString  = 'name=' + name_val + '&username=' + username_val;  
 
        $.ajax({
 
        type: 'POST',
        url: 'check_availability.php',
        data : dataString,
 
        success: function(response)
                {  
                                if (response != 'ok')
                {
                        $(this).parent().find('.eMsg').html('<img src="error.png" width="20" height="20" align="absmiddle"> Le pseudo que vous avez choisis est deja en utilisation!');
                        $(".sAvailable").html('');
 
                $(this).parent().find('#username').css(
                        "border-color", "#FF0000",
                        "border-width", "1px"
                          );
 
                        return false;
                        }
                        else
                        {
 
                                $(".sAvailable").html('');                     
                                $(".sAvailable").html('<img src="success.png" width="20" height="20" align="absmiddle"> Le pseudo <b>' + username_val + '</b> est disponible');
 
                $(this).parent().find('#username').css(
                        "border-color", "#badfac",
                        "border-width", "1px"
                          );
                        return true;
 
                        }
                        }
                        });
 
                        return true;
 
 
                } // end else
                } // end username_check function
 
        name.blur(check_name);
        username.blur(check_username);
 
        // en gros, la soumission de la form
        frm_login.submit(function(){
                if(check_name() & check_username())
                        return true;
                else
                        return false;
        });
 
 
 return false;
 }); // end DOM function
 
</script>
 
 
</head>
<body>
<?php
include 'site_vars.php';
 
    echo '<form name="frm_login" id="frm_login" action="#" method="POST">';
    echo '<div class="frm_fields">';
    echo '<label for="name" id="label01">'.$name_var.'</label>';
    echo $name_input;
    echo '<span class="info"></span>'; // pour afficher les infos
    echo '<span class="eMsg"></span>'; // en cas d'erreur
    echo '<span class="sMsg"></span>'; // en cas de success
    echo '</div>';
 
    echo '<div class="frm_fields">';
    echo '<label for="username" id="label01">'.$username_var.'</label>';
    echo $username_input;
    echo '<span class="info"></span>'; // pour afficher les infos
    echo '<span class="eMsg"></span>'; // en cas d'erreur
    echo '<span class="sMsg"></span>'; // en cas de success
    echo '<span class="sAvailable"></span>'; // en cas de validite
    echo '<span class="Checking"></span>'; // en cas de verification
 
    echo '</div>';
 
    echo '<div class="frm_fields">';
    echo '<label for="email" id="label01">'.$email_var.'</label>';
    echo $email_input;
    echo '<span class="info"></span>'; // pour afficher les infos
    echo '<span class="eMsg"></span>'; // en cas d'erreur
    echo '<span class="sMsg"></span>'; // en cas de success
    echo '</div>';
 
    echo '</span>';
 
    echo $submit_var;
 
    echo '</form>';
?>
 
</body>
</html>
Merci