ZhuCeController.class.php
namespace Home\Controller;
use Think\Controller;
class ZhuCeController extends Controller
{
function ZhuCe()
{
$cw ="";
if(!empty($_GET))
{
$cw = $_GET["cw"];
}
if(empty($_POST))
{
$this->assign("error",$cw);
$this->display();//打出注册页面
}
else
{
$model = new \Home\Model\testModel();//创建子类模型
//$model = D("test");//创建模型
//$z = $model->create();//自动收集表单,用Tp进行表单验证必须使用这个create 方法
//var_dump($model);
if(!$model->create())//如果验证失败
{
$e = $model->getError();//如果失败输出失败信息
$url = "ZhuCe/cw/{$e}";
$this->error("注册失败","$url",1);
}
else
{
$model->add();//验证成功直接添加
}
}
}
ZhuCe.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="__ACTION__" method="post"><!--提交到当前控制器-->
<div>用户名:<input type="text" name="uid" /></div>
<div>密 码:<input type="text" name="pwd" /></div>
<div>确认密码:<input type="text" name="pwd1" /></div>
<div>年龄:<input type="text" name="age" /></div>
<div>邮箱:<input type="text" name="email" /></div>
<div>名字:<input type="text" name="name" /></div>
<div><{$error}></div>
<input type="submit" value="注册" />
</form>
</body>
</html>