zoukankan      html  css  js  c++  java
  • 表单验证(注册)

    ZhuCeController.class.php
    
    
    namespace HomeController;
    use ThinkController;
    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 HomeModel	estModel();//创建子类模型
                //$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>密&nbsp;&nbsp;码:<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>
  • 相关阅读:
    div 内容自动换行
    发邮件
    asp gridview
    授权 注册
    asp grid 增加和删除行数据
    计算两个日期相差的天数
    sql 删除数据库表 外键
    装完Centos7提示Initial setup of CentOS Linux 7 (core)(转载)
    如何用javac 和java 编译运行整个Java工程 (转载)【转】在Linux下编译与执行Java程序
    centos7 安装拼音输入法(转载)
  • 原文地址:https://www.cnblogs.com/erinzhismile/p/5606785.html
Copyright © 2011-2022 走看看