Hi,
I am working on a login form verification. I try to write my own server side custom validation, then send back the response to the client and then display in the browser without using dhtmlxconnector. But i am still confusing about the whole process, i tried the following code, but it is not working. Is any thing wrong? Could anyone help me with that. I will appreciate it a lot!
Thank you very much!
Here is my code:
Client Side:
var loginData =[
{type:"label",label:"Enter Your Login Information:", offsetLeft:"50px"},
{type: "hidden", name:"result", value:""},
{type:"input",name:"userName",label:"User Name",validate:"ValidEmail", inputWidth:150,offsetTop:10,labelWidth:100},
{type:"password",name:"password",label:"Password", validate: "NotEmpty",inputWidth:150,offsetTop:10,labelWidth:100},
{type:"button",name:"apply", value:"Enter", command:"save",offsetTop:10}
];
var loginForm = layout.cells("a").attachForm(loginData);
loginDP = new dataProcessor("../Controller/procLogin.php");
loginDP.init(loginForm);
loginDP.defineAction("error",function(response) {
var msg = response.getAtrribute("msg");
alert(msg);
});
loginForm.attachEvent("onValidateError", doCustomErrorHandle);
function doCustomErrorHandle(name,value,res)
{
if(name == "userName")
{
alert("Invalid UserName");
}
if(name == "password")
{
alert("Password should not be empty");
}
}
loginForm.attachEvent("onButtonClick", function(name, command){
if(name == "apply")
{
userName = loginForm.getItemValue("userName");
password = loginForm.getItemValue("password");
this.send("../Controller/procLogin.php","post");
}
});
Server Side:
[code]<?php
header("Content-type:text/xml");
ini_set('max_execution_time', 7000);
print("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>“);
include (“c:\windows\include\db_connect_mmc.inc”);
$userName = $_POST[‘userName’];
$password = $_POST[‘password’];
$query = mysqli_query($link,“select groupName from user_info_table where userName = ‘$userName’ and password = ‘$password’”);
//If there is at least one row valid, we process the next step.
if($query)
{
while($row = mysqli_fetch_array($query))
{
$_GLOBAL[‘groupName’] = $row[‘groupName’];
}
$group = $_GLOBAL[‘groupName’];
if($group != “”)
{
print(”“);
print(”“);
print(”");
}
else
{
print("<data>");
print("<action type='error'user='$userName' msg = 'No group Asigned'/>");
print("</data>");
}
}
else
{
print("<data>");
print("<action type='error' user='$userName' msg = 'No Such User'/>");
print("</data>");
}
mysqli_close($link);
?>
[/code]