6月17日 TP表单验证
2016-06-21 10:08
495 查看
用做验证登录格式
ZhuCeController.class.php:
静态验证:
ZhuCe.html:
testModel.class.php:
动态验证:
ZhuCeController.class.php:
YanZheng.html:
ZhuCeController.class.php:
<?php namespace Home\Controller; use Think\Controller; class ZhuCeController extends Controller { //静态验证 function ZhuCe() { if(empty($_POST)) { $this->display(); } else { $model = new \Home\Model\testModel(); if(!$model->create()) { exit($model->getError()); } else { $model->add(); } } } //动态验证 function YanZheng() { $cw = ""; if(!empty($_GET)) { $cw = $_GET["cw"]; } if(empty($_POST)) { $this->assign("error",$cw); $this->display(); } else { $mmodel = new \Home\Model\testModel(); $rules = array( array('uid','require','用户名不能为空'), array('pwd','require','密码不能为空'), array('pwd','pwd1','两次输入的密码不一致',1,'confirm'), array('age','18,50','年龄必须在18到50之间',1,'between'), array('email','email','邮箱格式输入不正确'), ); if(!$model->validate($rules)->create()) { echo $model->getError(); } } } }
静态验证:
ZhuCe.html:
<body> <h1>注册页面</h1> <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> <input type="submit" value="注册" /> </form> </body>
testModel.class.php:
<?php namespace Home\Model; use Think\Model; class testModel 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','邮箱格式输入不正确'), ); }
动态验证:
ZhuCeController.class.php:
<?php namespace Home\Controller; use Think\Controller; class ZhuCeController extends Controller { //动态验证 function YanZheng() { $cw = ""; if(!empty($_GET)) { $cw = $_GET["cw"]; } if(empty($_POST)) { $this->assign("error",$cw); $this->display(); } else { $mmodel = new \Home\Model\testModel(); $rules = array( array('uid','require','用户名不能为空'), array('pwd','require','密码不能为空'), array('pwd','pwd1','两次输入的密码不一致',1,'confirm'), array('age','18,50','年龄必须在18到50之间',1,'between'), array('email','email','邮箱格式输入不正确'), ); if(!$model->validate($rules)->create()) { echo $model->getError(); } } } }
YanZheng.html:
<body> <h1>注册页面</h1> <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>
相关文章推荐
- TP学习笔记
- 用ChrootDirectory限制SFTP登录的用户只能访问指定目录且不能进行ssh登录
- 将vim打造成php的IDE开发环境
- yii\base\InvalidConfigException The directory is not writable by the Web process
- vsftp的默认目录那点事
- yii2 session处理
- SFTP上传文件详解
- laravel运行composer update时出现如下错误信息的解决方案
- [李景山php]每天laravel-20160904|Dispatcher-4
- [李景山php]每天laravel-20160904|Dispatcher-4
- 6月17日 TP框架增删改查
- POI——CTPhoneticRun异常解决
- ThinkPHP框架之模型
- jfinal的getpara取值
- OutputDebugString函数
- ContentProvider之访问者(二)
- ContentProvider 被访问的(一)
- PHP中的字符串连接运算符
- PHP分页初探 一个最简单的PHP分页代码的简单实现
- 浅谈PHP eval()函数定义和用法