Form ServerSide Custom Validation, Client Side Catch Error

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]

There are two different ways for data savingg

a) using dataprocessor - usefull if you have many records of the same type and want to creaete the unified way to process the data.

b) using manual data sending - can be used if you need to process the form in some specific way.

In case of login form the solution (b) is more simple

You can

  • remove all dataparocessor related logic ( you need not it, if you are using form.send )
  • on server side, return status code in any custom format - there is no need to define it as xml

If you want to use dataprocessor, instead of this.send(…) you need to use this.save(); but in such case parameters on server side will be send with different ( more complex ) naming.

Hi Stanislav,

Thank you very much for your reply. I have solved the problem according to you hint.

Can you post your final code I am having the same problem