Bonjour,

j'ai deja réalisé ce genre de manipulation mais sur mon code ajax je suis un peu bloqué.

en effet, sur ce code je vérifie dèjà l'existence de certains champs dans ma bdd.

si les champs n'existe pas : l'upload est obligatoire (j'ai fais une vérif avant l'envoi des fichiers ça fonctionne)

si le champs existe l'upload est facultative donc je ne vérifie pas.

j'ai bien réalisé ce mécanisme mais je veux ajouter dans mon onsubmit du form le nom de la fonction pour bloquer l'envoi.

je vous montre mon code un peu long mais pas trop compliqué avec la variable bUpload qui est false par défaut mais qui n'est pas mise a jour correctement.

et la fonction testUpload qui doit bloquer ou pas l'envoi.

verif.js
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
// ce code va vérifier la disponibilité du Nom de fichier SOURCE (attention le statut est associé au fichier)
//on pourra avoir deux meme noms de fichiers source mais le statut sera différent
//adaptation au form edition : si le statut est modifier lupload est obligatoire sinon il est facultatif
 
var bUpload = false;
function req_NomFichierSource(NomFichierSource) {
 
	//XMLHttpRequest est supporté par Internet Explorer 5.0+, Safari 1.2, Mozilla 1.0 / Firefox, Netscape 7
	if(document.all) var XhrObj = new ActiveXObject("Microsoft.XMLHTTP"); //Internet Explorer
	else var XhrObj = new XMLHttpRequest(); //Mozilla
 
	//content = document.getElementById("NomFichierSource_check"); 	//zone d'affichage
	var content = document.getElementById("NomFichierSource_check"); 	//zone d'affichage
	var srcFile = document.getElementById("NomFichierSource");
	var statut = document.getElementById("StatutCorpus");
 
	//fichierSON
	var fichierSON = document.getElementById("fichierSON");
	var fichierTRS = document.getElementById("fichierTRS");
 
	XhrObj.open("POST", "../verif_modif_js/verif_StatutCorpus.php");
	//XhrObj.open("POST", "verif_NomFichierSource.php", false);
	//Ok pour la page cible
	XhrObj.onreadystatechange = function()
	{
		if (XhrObj.readyState == 4 && XhrObj.status == 200) {
			if (XhrObj.responseText == 'OK') {
				content.innerHTML='<img src="../css/images/accepter.png" alt=""/><br><label>Upload obligatoire</label>';
				 // ok nouveau pseudo
 
				//=================================verification champs parcourir non vide=====================================//
				$.fn.copyTo = function(to) {
				    var to = $(to);
				    for ( var i = 1; i < arguments.length; i++ )
				        to.set( arguments[i], this.get(0)[ arguments[i] ] );
				    return this;
				};
 
				new function() {
				       // $.fn.validate = validate() {};
				    $.fn.validate = {
				        init: function(o) {
 
				          if(o.name == 'email') { this.email(o) };
				          if(o.name == 'fichierSON') { this.fichierSON(o) };
				          if(o.name == 'fichierTRS') { this.fichierTRS(o) };
				        },
 
 
 
				        email: function(o) {
				          var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				           if (o.value.match(email)) {
				              doSuccess(o);
				            } else {
				              doError(o,'email incorrect');
				            };
				        },
				        ///fichierSON
				        fichierSON: function(o) {
				          var fichierSON  = "^.{2,}(.wav|.mp3|.wma)$";
				            if (o.value.match(fichierSON)) {
				              doSuccess(o);
 
				            } else {
				              doError(o,'<label>Joindre un fichier son correct!!</label>');
 
				            };
				        },
				        fichierTRS: function(o) {
					          var fichierTRS  = "^.{2,}(.trs|.doc|.txt)$";
					            if (o.value.match(fichierTRS)) {
					              doSuccess(o);
 
					            } else {
					              doError(o,'<label>Joindre un fichier transcription correct!!</label>');
 
					            };
					        }
 
				     };
 
				     function doSuccess(o) {
				              $('#' + o.id + '_img').html('<img src="../css/images/accept.gif" border="0" style="float:left;" />');
				              $('#' + o.id + '_li').removeClass("error");
				              $('#' + o.id + '_msg').html("");
				              $('#' + o.id + '_li').addClass("success");
				     }
 
				     function doError(o,m) {
				              $('#' + o.id + '_img').html('<img src="../css/images/exclamation.gif" border="0" style="float:left;" />');
				              $('#' + o.id + '_li').addClass("error");
				              $('#' + o.id + '_msg').html(m);
				              $('#' + o.id + '_li').removeClass("success");
				     }
				     //private helper, validates each type after check
				     function doValidate(o) {
				        	$('#' + o.id + '_img').html('<img src="../css/images/loading.gif" border="0" style="float:left;" />');
				        	$.post('ajax.php', { id: o.id, value: o.value }, function(json) {
				                  	eval("var args = " + json);
				                        if (args.success == true)
				                  	{
				                  	  doSuccess(args);
 
 
				                  	}
				                  	else
				                  	{
				                  		 bUpload = false;
				                          doError(args,args.msg);
 
 
				                  	}
				                  });
				    };
 
				};
				$.fn.match = function(m) {
					$('#' + this.get(0).id + '_img').html('<img src="../css/images/loading.gif" border="0" style="float:left;" />');
					if ($(this).get(0).val() == $(m.match).val()) {
				          $('#' + this.get(0).id + '_img').html('<img src="../css/images/accept.gif" border="0" style="float:left;" />');
				          $(m.error).removeClass("error");
				          $(m.error).addClass("success");
				          $('#' + this.get(0).id + '_msg').html("");
				        } else {
				          $('#' + this.get(0).id + '_img').html('<img src="../css/images/exclamation.gif" border="0" style="float:left;" />');
				          $(m.error).addClass("error");
				          $(m.error).removeClass("success");
				          $('#' + this.get(0).id + '_msg').html("The passwords don't match, please try again");
				        };
				};
				$(document).ready(function()
				{
 
				  $("//[@class=validated]/input").blur(function() {
				          $(this).validate.init(this);
				  });
 
 
 
				  // This Used To Be HOVER, But I.E. Didnt Like It
				  // $(".form
					// li").hover(function(){$(this).addClass("selected");},function(){$(this).removeClass("selected");});
				  $(".form li").mouseover(function() {
				          $(this).addClass("selected");
				  });
				  $(".form li").mouseout(function() {
				          $(this).removeClass("selected");
				  });
				});
				//==============================fin de la vérification des champs====================================//
			} else {
				content.innerHTML='<img src="../css/images/refuser.png" alt=""/><br><label>Upload facultatif</label>';
				bUpload = true; // erreur pseudo déjà existant
			}
		}
	}
 
	XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	//XhrObj.send('p='+encodeURIComponent(NomFichierSource));
	XhrObj.send('p='+encodeURIComponent(srcFile.value)+'&s='+encodeURIComponent(statut.value));
 
 
 
 
 
}
 
///A METTRE DANS LE ON SUBMIT AVEC LES CONDITIONS VALABLES
function testUpload(f) {
 
 
 
	if (!bUpload) {
	 alert('Joindre le fichier son et/ou transcription!!');
	 return false;
	}
 
	return true;
 
 
 
 
 
 
 
	}

merci