


TP3.2 Example analysis of how to implement online message submission verification code function
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:
<p class="message-con clearfix"> <p class="mcon-left pic pull-left"><img src="/Public/Admin/xx/images/message.png" class="vcenter" alt="" /></p> <p 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="#" rel="external nofollow" >看不清楚?换一张</a><em>*</em></label> <label><input type="submit" class="msub" name="tj" value="在线提交" /></label> </form> </p> </p> </p>
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:
<?php namespace Otcms\Model; use Think\Model; class UserModel extends Model{ protected $_validate = array( array('xingming','require','姓名不可空!'), array('tel','require ','手机号不可空!'), array('dizhi','require','地址不可空!'), array('youxiang',' require','邮箱不可空!'), array('content','require','内容不可空!'), ); }
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use Laravel to develop an online restaurant reservation system In recent years, with the rapid development of the Internet and mobile Internet, online reservations have become an indispensable part of modern people's lives. The catering industry is no exception. More and more restaurants are beginning to provide online reservation services to improve user experience and expand market share. This article will introduce how to use the Laravel framework to develop a simple but fully functional online restaurant reservation system, and provide specific code examples to facilitate readers to learn and practice. Environment setup First, we need

Xianyu APP is a super second-hand trading software. It allows everyone to choose products here at will, or publish their own products for sale. There is no problem. Everything can be realized here. When you use it here When using the Xianyu APP, everyone needs to communicate in a timely manner by leaving messages to get more information and help you sell or buy goods better. It is relatively convenient and is aimed at those who still don’t know how to leave messages on Xianyu. For my friends, I have now brought you specific Xianyu message tutorials. I hope it will be helpful to you. Xianyu message tutorial: 1. First, open Xianyu. 2. Then enter the interface and click on a product. 3. Then in the interface that appears, slide up and click

With the popularity of e-commerce, more and more businesses are adopting online invoice management systems to manage sales and invoices. When developing an online invoice management system, it is important to choose the right tools and technology. This article will introduce how to use PHP language to develop an online invoice management system and provide some useful development guidelines. Determine system requirements Before starting development, the specific requirements for an online invoice management system need to be determined. This may include the following aspects: Invoice management: saving, querying and editing invoice information; Customer information management: saving, querying and editing customers

How to use JavaWebsocket to implement online audio and video calls? In today's digital age, real-time communication is becoming more and more common. Whether it is remote collaboration at work or remote communication with relatives and friends at home, real-time audio and video calls have become an indispensable part of people. This article will introduce how to use JavaWebsocket to implement online audio and video calls, and provide specific code examples. 1. Understand WebsocketWebsocket is a new technology in HTML5

How to use PHP to implement a simple online music player. With the advent of the digital age, more and more people are beginning to enjoy music through the Internet, and online music players have become an important tool. In this article, we will implement a simple online music player through the PHP programming language and provide specific code examples. Preparation work: Before starting, we need to prepare the following aspects: a machine running a web server (such as Apache). PHP running environment. Music files, music files can be

How to use PHP to implement a simple online event registration system. With the rapid development of the Internet, more and more activities are beginning to manage the registration process through online registration systems, eliminating the trouble of traditional paper registration forms and manual processing. This article will introduce how to use PHP language to implement a simple online event registration system, and use specific code examples to help readers understand and practice. System Requirements Analysis Before developing a system, it is first necessary to clarify the requirements and functions of the system. According to the characteristics of the event registration system, we can determine the following

How to use Laravel to develop an online customer service system Introduction: Online customer service systems play an important role in modern enterprises. It helps businesses communicate with customers in real time, answer questions, provide support, and enhance user experience. This article will introduce how to use the Laravel framework to develop a simple and practical online customer service system. 1. Design the database The online customer service system needs to store users and conversation records, so it is first necessary to design a suitable database model. In Laravel we can use the migration tool

How to use PHP to implement a simple online order management system 1. Introduction Online order management system is a common e-commerce application. It can help merchants effectively manage the order process, speed up order processing, and improve customer satisfaction. This article will introduce how to use PHP to implement a simple online order management system, including the creation, modification, query and deletion of orders. This article assumes that readers already have some basic knowledge of PHP. 2. System Requirements The online order management system needs to meet the following basic requirements: Login function
