码迷,mamicode.com
首页 > 其他好文 > 详细

静态表单验证

时间:2016-06-30 12:20:52      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

写操作方法

function zhuce()
	{
		$cwxx="";
		if(!empty($_GET))
		{
		   $cwxx=$_GET["cw"];	
		}
		if(empty($_POST))
		{
			$this->assign("zhi",$cwxx);
			$this->display();
		}
		else
		{
			$dl=new \Home\Model\dlModel();
			if(!$dl->create())
			{
				$cw=$dl->getError();
				$pin="zhuce/cw/{$cw}";
				
				$this->error("注册失败",$pin);
			}
			else
			{
				$dl->add();
			}
		}
	}

  在Home下面的Model里面建模型

<?php
namespace Home\Model;
use Think\Model;
class dlModel extends Model
{
	protected $_validate = array(
	   array("uid","require","用户名不能为空"),    //正则验证后面不用写
	   array("pwd","require","密码不能为空"),
	   array("pwd","pwd1","两次密码输入不一致",1,"confirm"),
	   //年龄验证  array("age","18,50","年龄必须在18到50之间",1,between)
	   //验证邮箱  array("email","email","邮箱格式不正确")
	);
}

 显示页面代码

<!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="name" /></div>
</br>
<div><{$zhi}></div>
</br>
<input type="submit" value="注册" />
</form>
</body>
</html>

  网页显示

技术分享

静态表单验证

标签:

原文地址:http://www.cnblogs.com/wcc731546227/p/5629410.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!