This article is mainly for everyone to introduce the TP3.2 to write the verification code verification, with a certain reference value, interested in small partners can refer to
How to implement verification Code success verification function? Submit a verification code? This article is for everyone to answer.
Tidy up what you have mastered today, or else I'll forget it:
Today in a corporate website, there is a function of the online message, the final submission of the need to enter a verification code. Under
Of course, the connection is not my backstage.
OK, here we go, first I need to show the verification code, the front page:
<p class= "Message-con clearfix" > <p class= "mcon-left pic pull-left" ></p> <p class=" Mcon-right pull-right "> <form method=" POST " Action= "{: U (' Validate ')}" Name= ' Valiate ' > <label><span> name </span><input type= "text" Name= " Xingming "class=" Mname "value=" "/><em>*</em></label> <label><span> Contact Phone </span ><input type= "Text" name= "tel" class= "Mtel"/><em>*</em></label> <label><span > Contact Address </span><input type= "text" name= "Dizhi" class= "Madd"/></label> <label><span> e-mail address </span><input type= "text" name= "Youxiang" class= "Memail"/></label> <label><span> Message content </span><textarea name= "content" class= "Mcontent" ></textarea><em>*</em></ label> <label class= "Mcodela" ><input type= "text" name= "code" class= "Mcode"/> <a href=" # "rel=" external nofollow "> can't see clearly? Change one </a><em>*</em></label> <label><input type= "Submit" class= "Msub" name= "TJ" value = "Online submission"/></label> </form> </p> </p> </p>
Good click event, name, Submit button has been changed, go, go to controller;
Come to the controller here, do one thing first, introduce model bar:
Use Otcms\model;
There's no model class to write for yourself:
<?phpnamespace otcms\model;use think\model;class Usermodel extends model{protected $_validate = Array ( ' Xingming ', ' require ', ' the name is not empty! '), Array (' tel ', ' require ', ' mobile phone number is not available! '), array (' Dizhi ', ' require ', ' Address not empty! '), array (' Youxiang ', ' Require ', ' Mailbox not empty! '), array (' content ', ' require ', ' contents are not empty! '), );}
To set the verification code:
Show:
Public Function Verify () { $config = array ( ' fontSize ' = + 30,//captcha font size ' length ' = 4,/ / Verification code number ); $verify = New\think\verify ($config); $verify->entry (); }
Below to write the conditions:
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 ()) { //If the creation fails to indicate that validation did not pass the output error message exit ($fkyz->geterror ()); } else{ //validation can be done by other data operations $verify = new \think\verify (); $yzmyz = $verify->check ($YZM); if (! $yzmyz) { $this->error (' captcha error '); } else{ $validate = M ("Liuyan"); $validate->add ($date); $this->success (' Add success '); } } }
Figure: