Alright, I have an AJAX Username checker which goes to check.php with ?user=NAME and I want it so when it returns something with 'Not Available' in it, it will disable the form field.
This is what I have:
Register.php
check.jsCode:<?php if($settings->reg_stats == 0){ $Functions->openblock("Registrations Disabled","par"); print "Site registrations have been disabled"; $Functions->closeblock("par"); }else{ if(!$_POST['register']){ $Functions->openblock("Register","frm", "/register/", null, 'reg_frm'); print "<strong>Username</strong>:<br /> <input type=\"text\" name=\"username\" onchange=\"CheckItems(this.value, 'user');\" /> </p> <div id=\"user_results\"></div> <p> <strong>Password</strong>:<br /> <input type=\"password\" name=\"pass\" onchange=\"CheckItems(this.value, 'pass');\" /> </p> <div id=\"pass_results\"></div> <p> <strong>Verify Password</strong>:<br /> <input type=\"password\" name=\"vpwd\" onchange=\"CheckItems(this.value, 'vpass');\" /> </p> <div id=\"vpass_results\"></div> <p> <strong>E-mail</strong>:<br /> <input type=\"text\" name=\"mail\" /><br /> <strong>Verify E-mail</strong>:<br /> <input type=\"text\" name=\"vmail\" /><br /> <input type=\"submit\" name=\"register\" disabled=\"false\" />"; $Functions->closeblock("frm"); }else{ } } ?>
check.phpCode:var xmlHttp function GetXmlHttpObject(){ var objXMLHttp=null if (window.XMLHttpRequest){ objXMLHttp=new XMLHttpRequest() }else if (window.ActiveXObject){ objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") } return objXMLHttp } function CheckItems(text, type){ xmlHttp=GetXmlHttpObject() if (xmlHttp==null){ alert ("Browser does not support HTTP Request") return } var url="http://SITE/check.php?text=" + text + "&type=" + type xmlHttp.open("GET",url,true) xmlHttp.onreadystatechange = function () { if (xmlHttp.readyState == 4) { document.getElementById(type + "_results").innerHTML = xmlHttp.responseText; if (xmlHttp.responseText.contains == "Not Available"){ document.reg_frm.register.disabled = true; }else{ document.reg_frm.register.disabled = false; } } }; xmlHttp.send(null); }
Any help? u.uCode:<?php require ('FileLibrary/configuration.db.php'); switch ($_GET['type']) { default: print "No Type Defined!"; break; case 'user': $user = stripslashes(strip_tags(htmlspecialchars($_GET['text'], ENT_QUOTES))); $check = $db->dbCount($db->dbQuery("SELECT * FROM `" . DB_PREFIX . "users` WHERE `username` = '" . $user . "'")); if ($check == 0) { echo '' . $user . ' is <span style="color:#009933">Available!</span>'; } elseif ($check > 0) { echo '' . $user . ' is <span style="color:#CC0000">Not Available!</span>'; } break; case 'pass': case 'vpass': $password = $_GET['text']; $strength = 0; if (preg_match("/([a-z]+)/", $password)) { $strength++; } // letters (uppercase) if (preg_match("/([A-Z]+)/", $password)) { $strength++; } // numbers if (preg_match("/([0-9]+)/", $password)) { $strength++; } // non word characters if (preg_match("/(W+)/", $password)) { $strength++; } if ($_GET['type'] == 'pass') { $def_str = '<strong>Password Strength</strong>: '; } else { $def_str = '<strong>Verification Password Strength</strong>: '; } switch ($strength) { default: echo $def_str . "<span style=\"color:red; text-decoration:underline;\">None Given!</span>"; break; case "1": //red echo $def_str . "<span style=\"color:red;\">Very Weak</span>"; break; case "2": //yellow echo $def_str . "<span style=\"color:yellow;\">Weak</span>"; break; case "3": //orange echo $def_str . "<span style=\"color:orange;\">Strong</span>"; break; case "4": //green echo $def_str . "<span style=\"color:green;\">Very Strong</span>"; break; } break; } ?>


LinkBack URL
About LinkBacks



Reply With Quote



