AJAX php: vérifier si un user est déjà enregistré sans avoir à re-charger la page
PHP:
-
function RemoteRequestObject()
-
{
-
var A = false;
-
try { A = new ActiveXObject(“Msxml2.XMLHTTP”); }
-
catch(e)
-
{ try { A = new ActiveXObject(“Microsoft.XMLHTTP”); }
-
catch(err) { A = false; }
-
}
-
-
if(!A && typeof(XMLHttpRequest) != ‘undefined’)
-
A = new XMLHttpRequest();
-
return A;
-
}
-
-
function validateUser(oForm) {
-
var x = RemoteRequestObject();
-
oForm.onsubmit = function()
-
{
-
-
if (oForm.annee.value==“annee”) {
-
alert(“Entrez votre année de naissance”);
-
oForm.annee.focus();
-
return false;
-
-
}
-
if (oForm.email.value.indexOf(“@”) == -1 || oForm.email.value.indexOf(“.”) == -1 || oForm.email.value == “”)
-
{
-
alert(“Veuillez entrer un email valide”);
-
oForm.email.focus();
-
return false;
-
}
-
-
if (oForm.pseudo.value==“”) {
-
alert(“Choissez un pseudo”);
-
oForm.pseudo.focus();
-
return false;
-
}
-
if (oForm.motdepasse.value==“”) {
-
alert(“Choissez un mot de passe”);
-
oForm.motdepasse.focus();
-
return false;
-
}
-
-
if (oForm.cgu.checked==false) {
-
alert(“Vous devez accepter les conditions générales d’utilisation”);
-
oForm.cgu.focus();
-
return false;
-
-
}
-
-
var usr=oForm.elements[‘pseudo’].value;
-
var url = “ajax.php?pseudo=”+usr;
-
x.open(“GET”,url,true);
-
x.onreadystatechange=function()
-
{
-
if(x.readyState == 4 && x.status == 200)
-
{
-
var r = x.responseText;
-
if(r.indexOf(“OK”) == 0)
-
{
-
oForm.submit();
-
}
-
else
-
{
-
alert(“Le pseudo que vous avez choisi est déjà utilisé!\nVeuillez le changer!”);
-
form3.pseudo.focus();
-
}
-
}
-
};
-
x.send(null);
-
return false;
-
}
-
-
}
Le fichier ajax.php contient
PHP:
0 Responses to “easyphp et url rewriting”
Leave a Reply