gt;
<tr align="center">
<td colspan="2"><input type="submit" name="submitButton" value="提交" class="button" />
<input type="reset" name="Submit2" value="重置" class="button" /></td>
</tr>
</table>
</div>
</div>
</form>
</body>
</html>
点提交后执行singup.php里的processForm函数
3、inc/singup.php
复制代码 代码如下:
<?php
define (''XAJAX_DEFAULT_CHAR_ENCODING'', ''gb2312'' );
//注意这里,必须要设置gb2312,不然中文会乱码
require_once("xajax.inc.php");
require_once("function.php");
$xajax = new xajax();
$xajax->registerFunction("processForm");
//同reg.php文件
function processForm($aFormValues)
{
$objResponse = new xajaxResponse();
require_once("conn.php");
$usr=$aFormValues[''usr''];
$email=$aFormValues[''email''];
$pwd=$aFormValues[''pwd''];
$pw=Md5($pwd);
$errmsg="";
//要过滤的非法字符
$ArrFiltrate=array("''",";","union");
foreach($aFormValues as $key=>$value){
if (FunStringExist($value,$ArrFiltrate)){
$objResponse->addAlert("输入的信息含有非法字符\"'' ; union!\"");
$objResponse->addAssign("submitButton","value","继续");
$objResponse->addAssign("submitButton","disabled",false);
return $objResponse;
}
}
if (trim($usr) == "")
{
$errmsg.="请输入用户名!\n";
}
if (trim($pwd) == "")
{
$errmsg.="请输入密码!\n";
}
if ($pwd != $aFormValues[''pwd2''])
{
$errmsg.="两次输入的密码不一致!\n";
}
if (!CheckEmailAddr($email))
{
$errmsg.="邮件地址不正确!\n";
}
$sql="select * from zl_usr where zl_usr=''$usr''";
$result=mysql_query($sql,$db);
if($myrow=mysql_fetch_array($result)){
$errmsg.="用户名已经存在!\n";
}
if ($errmsg=="")
{
$sForm = "注册成功<br>用户名:".$usr."<br>email:".$email."";
$sql="insert into zl_usr(zl_usr,zl_pwd,email) values(''$usr'',''$pw'',''$email'')";
$result=mysql_query($sql,$db);
$objResponse->addAssign("formDiv","innerHTML",$sForm);
}
else
{
$objResponse->addAlert($errmsg);
//弹出错误信息
$objResponse->addAssign("submitButton","value","继续");
//修改submitButton的value为继续
$objResponse->addAssign("submitButton","disabled",false);
//修改submitButton这个按扭的属性
}
return $objResponse;
}
$xajax->processRequests();
?>
这个文件中对信息进行了有效性判断,包括:用户名是否已经注册过、信息中是否有非法字符、邮件地址是否正确、两次输入的密码是否一致,如果没有错误则输入到数据库中,并
$objResponse->addAssign("formDiv","innerHTML",$sForm);
在formDiv中重新插入代码,内容为$sForm
$sForm = "注册成功<br>用户名:".$usr."<br>email:".$email."";
如果有错误信息则
$objResponse->addAlert($errmsg);
//弹出错误信息
$objResponse->addAssign("submitButton","value","继续");
$objResponse->addAssign("submitButton","disabled",false);
//修改submitButton这个按扭的属性
3、login.php 登陆文件
复制代码 代码如下:
<?php
require_once("inc/xajax.inc.php");
$xajax = new xajax("inc/login.php");
$xajax->registerFunction("processForm");
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel=