zoukankan      html  css  js  c++  java
  • 6月17日 TP表单验证

    用做验证登录格式

    ZhuCeController.class.php:

    <?php
    namespace HomeController;
    use ThinkController;
    class ZhuCeController extends Controller
    {
        //静态验证
        function ZhuCe()
        {
            if(empty($_POST))
            {
                $this->display();
            }
            else
            {
                $model = new HomeModel	estModel();
                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 HomeModel	estModel();
            $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 HomeModel;
    use ThinkModel;
    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 HomeController;
    use ThinkController;
    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 HomeModel	estModel();
            $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>
  • 相关阅读:
    CCPlatformConfig(设置执行平台 iOS android win32等。。。)
    LeetCode Add Binary |My Solution
    actor中!(tell)与forward的差别
    二叉查找树(二叉排序树)创建,插入,删除操作。
    程序猿技术练级攻略
    poj 2236 Wireless Network 【并查集】
    leetcode 题解 || Letter Combinations of a Phone Number 问题
    创业之前 ——Paul Graham 最新博文
    linux-文件系统基本概念
    上拉电阻和下拉电阻的用处和区别
  • 原文地址:https://www.cnblogs.com/dongqiaozhi/p/5602681.html
Copyright © 2011-2022 走看看