zoukankan      html  css  js  c++  java
  • TP3.2写提交的验证码验证

    把今天掌握的东西整理一下,要不然,我就忘干净了:

    今天在做一个企业网站的时候,有一个在线留言的功能,最后提交的时候需要输入验证码。如图下:

    当然,特连接的并不是我的后台

    好了,开始了,首先我需要把验证码显示出来,前端页面:

    <div class="message-con clearfix">
                <div class="mcon-left pic pull-left"><img src="/Public/Admin/xx/images/message.png" class="vcenter" alt="" /></div>
                <div class="mcon-right pull-right">
                    <form method="post"  action="{:U('validate')}" name='valiate'> 
                    <label><span>姓名</span><input type="text" name="xingming" class="mname" value=""/><em>*</em></label>
                    <label><span>联系电话</span><input type="text" name="tel" class="mtel" /><em>*</em></label>
                    <label><span>联系地址</span><input type="text" name="dizhi" class="madd" /></label>
                    <label><span>邮箱地址</span><input type="text" name="youxiang" class="memail" /></label>
                    <label><span>留言内容</span><textarea  name="content" class="mcontent"></textarea><em>*</em></label>
                    <label class="mcodela"><input type="text" name="code" class="mcode" />
                        <img src="{:U('verify')}" onClick="this.src=this.src+'?'+Math.random();" alt="" />
                        <a href="#">看不清楚?换一张</a><em>*</em></label>
                    <label><input type="submit" class="msub" name="tj" value="在线提交" /></label>
                    </form>
                </div>
            </div>
        </div>

    好 点击事件,name,提交按钮都改好了,走起,去控制器啦;

    来到控制器这里,先做一件事,引入model吧:

    use OtcmsModel;

    啥?没有model类  自己去写吧:

    <?php
    namespace OtcmsModel;
    use ThinkModel;
    class UserModel extends Model{
        protected $_validate = array(
    
            array('xingming','require','姓名不可空!'),
            array('tel','require ','手机号不可空!'),
            array('dizhi','require','地址不可空!'),
            array('youxiang',' require','邮箱不可空!'),
            array('content','require','内容不可空!'),
        );
    }

    设置验证码:

    显示:

     public function verify(){
    
            $config =    array(
                'fontSize'    =>    30,    // 验证码字体大小
                'length'      =>    4,     // 验证码位数
            );
    
            $verify = newThinkVerify($config);
            $verify->entry();
    
        }

    下面来写条件:

     public function validate(){
            $date['xingming'] = I('post.xingming');
            $date['tel'] = I('post.tel');
            $date['dizhi'] = I('post.izhi');
            $date['youxiang'] = I('post.youxiang');
            $date['content'] = I('post.content');
            $yzm = I('post.code');
    
            $fkyz = D("Liuyan");
    
            if (!$fkyz->create()){
                // 如果创建失败 表示验证没有通过 输出错误提示信息
                exit($fkyz->getError());
    
            }else{
            
                // 验证通过 可以进行其他数据操作
                $verify = new ThinkVerify();
                $yzmyz = $verify->check($yzm);
    
                if(!$yzmyz){
    
                    $this->error('验证码错误');
    
                }
                else{
                    $validate = M("liuyan");
                    $validate->add($date);
                    $this->success('添加成功');
    
                }
            }
        }

    图:

     

      

  • 相关阅读:
    POJ 2506 Tiling
    POJ 2586 Y2K Accounting Bug
    POJ 2965 The Pilots Brothers' refrigerator (DFS)
    POJ 2499 Binary Tree
    POJ 3006 Dirichlet's Theorem on Arithmetic Progressions (素数)
    beautifulsoup 基本语法 含class属性查找小技巧class_
    xlrd库的使用
    pytest框架 里 fixture 参数化的方法
    ddt数据驱动
    mac电脑 pip安装包后 撞到了系统python里面的解决方法
  • 原文地址:https://www.cnblogs.com/xuan584521/p/7205826.html
Copyright © 2011-2022 走看看