Bonjour à tous,

Je souhaite réaliser la vérification des données saisies dans mon formulaire par appel à un fichier php (de manière à réaliser la vérification côté serveur). Pour ce faire, je dois utiliser un appel AJAX synchrone. Voici donc ce que j'ai pour l'instant.

Code Javascript : 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
function createConnection(){
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
 
	return xmlhttp;
}
 
function verificationFormulaire(){
 
	var connection = createConnection();
 
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			alert ('retour de fonction');
		}
	}
 
	connection.open ("POST", "http://www.malmundarium.be/inc/verification.php", false);
	var requete = "groupname="+document.getElementById("groupname").value;
	requete += "&grouppostal="+document.getElementById("grouppostal").value;
	requete += "&langue="+document.getElementById("langue").value;
	requete += "&participants="+document.getElementById("participants").value;
	requete += "&accompagnants="+document.getElementById("accompagnants").value;
	requete += "&datevisite="+document.getElementById("datevisite").value;
	requete += "&heurevisite="+document.getElementById("heurevisite").value;
	requete += "&respfirst="+document.getElementById("respfirst").value;
	requete += "&resplast="+document.getElementById("resplast").value;
	requete += "&respaddr="+document.getElementById("respaddr").value;
	requete += "&resptown="+document.getElementById("resptown").value;
	requete += "&resppostal="+document.getElementById("resppostal").value;
	requete += "&respphone="+document.getElementById("respphone").value;
	requete += "&respmail="+document.getElementById("respmail").value;
 
	connection.send(requete);
}
Au niveau de mon fichier formulaire, j'ai ceci :
Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
 
<form method="POST" name="reservationform" id="reservationform" action="./inc/reservation.php" >
<!-- tous les champs de mon formulaire -->
<input type="submit" name="" value="Envoyer" onClick="return verificationFormulaire();" id="" tabindex="23" />
</form>

Au niveau de mon fichier servant à la vérification des valeurs, j'ai ceci :
Code PHP : 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
<?php
 
$groupname = (!empty ($_POST['groupname'])) ? strip_tags($_POST['groupname']) : null;
$groupaddr = (!empty ($_POST['groupaddr'])) ? strip_tags($_POST['groupaddr']) : null;
$grouppostal = (!empty ($_POST['grouppostal'])) ? strip_tags($_POST['grouppostal']) : null;
$langue = (!empty ($_POST['langue'])) ? strip_tags($_POST['langue']) : null;
$participants = (!empty ($_POST['participants'])) ? strip_tags($_POST['participants']) : 0;
$accompagnants = (!empty ($_POST['accompagnants'])) ? strip_tags($_POST['accompagnants']) : -1;
$mobred = (!empty ($_POST['mobred'])) ? strip_tags($_POST['mobred']) : 0;
$datevisite = (!empty ($_POST['datevisite'])) ? strip_tags($_POST['datevisite']) : null;
$heurevisite = (!empty ($_POST['heurevisite'])) ? strip_tags($_POST['heurevisite']) : null;
$guided = (!empty ($_POST['guidee'])) ? strip_tags($_POST['guidee']) : 0;
$carnaval = (!empty ($_POST['carnaval'])) ? strip_tags($_POST['carnaval']) : 0;
$papier = (!empty ($_POST['papier'])) ? strip_tags($_POST['papier']) : 0;
$tresor = (!empty ($_POST['tresor'])) ? strip_tags($_POST['tresor']) : 0;
$respfirst = (!empty ($_POST['respfirst'])) ? strip_tags($_POST['respfirst']) : null;
$resplast = (!empty ($_POST['resplast'])) ? strip_tags($_POST['resplast']) : null;
$respaddr = (!empty ($_POST['respaddr'])) ? strip_tags($_POST['respaddr']) : null;
$resppostal = (!empty ($_POST['resppostal'])) ? strip_tags($_POST['resppostal']) : null;
$resptown = (!empty ($_POST['resptown'])) ? strip_tags($_POST['resptown']) : null;
$respcountry = (!empty ($_POST['respcountry'])) ? strip_tags($_POST['respcountry']) : null;
$respphone = (!empty ($_POST['respphone'])) ? strip_tags($_POST['respphone']) : null;
$respmail = (!empty ($_POST['respmail'])) ? strip_tags($_POST['respmail']) : null;
$montant = 0;
 
// if ( !$groupname || !$grouppostal || !$langue || !$participants || !$accompagnants || !$datevisite || !$heurevisite || !$respfirst || !$resplast || !$respphone ){
	// echo 'false';
	// exit;
// }
$erreur = ";";
if( $groupname == null)
	$erreur .= 'groupname='.$groupname.';';
if( $grouppostal == null)
	$erreur .= 'grouppostal='.$grouppostal.';';
if( $langue == null)
	$erreur .= 'langue='.$langue.';';
if( $participants == 0)
	$erreur .= 'participants='.$participants.';';
if( $accompagnants == 0)
	$erreur .= 'accompagnants='.$accompagnants.';';
if( $datevisite == null)
	$erreur .= 'datevisite='.$datevisite.';';
if( $heurevisite == null)
	$erreur .= 'heurevisite='.$heurevisite.';';
if( $respfirst == null)
	$erreur .= 'respfirst='.$respfirst.';';
if( $resplast == null)
	$erreur .= 'resplast='.$resplast.';';
if( $respphone == null)
	$erreur .= 'respphone='.$respphone.';';
 
if( $erreur==";")
	echo 'true';
else
	echo $erreur;
exit;
 
?>

Au niveau du code ajax, je n'obtiens jamais le message d'alerte 'retour de fonction'.

Qu'est ce que j'ai oublié ? Que dois-je envoyer comme valeur de retour à partir de mon code php de vérification ?

Je suis dans le cake pour l'instant, et ne m'y retrouve plus, quelqu'un peut-il me donner une bougie pour éclairer ma lanterne ?

En vous remerciant pour l'aide que vous pourrez m'apporter, je vous souhaite de passer une bonne après midi.