Home  >  Article  >  Backend Development  >  TP3.2 Example analysis of how to implement online message submission verification code function

TP3.2 Example analysis of how to implement online message submission verification code function

黄舟
黄舟Original
2017-07-20 13:47:581621browse

This article mainly introduces the verification code verification for writing and submitting in TP3.2 in detail. It has certain reference value. Interested friends can refer to

How to implement the verification code successful verification function. ? Submit verification code? This article gives you the answer.

Let me sort out what I have mastered today, otherwise I will forget everything:

When I was working on a corporate website today, there was an online message function, which I needed when submitting it at the end. enter confirmation code. As shown in the picture below:

Of course, the special connection is not my backend

Okay, here we go, first I need to display the verification code, Front-end page:


The click event, name, and submit button have all been changed. Let’s go to the controller;

Come to the controller Here, do one thing first, introduce the model:


use Otcms\Model;

What? There is no model class. Write it yourself:


Set verification code:

Display:


 public function verify(){

  $config = array(
   'fontSize' => 30, // 验证码字体大小
   'length'  => 4,  // 验证码位数
  );

  $verify = new\Think\Verify($config);
  $verify->entry();

 }

Write the conditions below:


 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 \Think\Verify();
   $yzmyz = $verify->check($yzm);

   if(!$yzmyz){

    $this->error('验证码错误');

   }
   else{
    $validate = M("liuyan");
    $validate->add($date);
    $this->success('添加成功');

   }
  }
 }

picture:

The above is the detailed content of TP3.2 Example analysis of how to implement online message submission verification code function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn