Two Verification code verification implementation, a direct in the form form submit button implementation validation, a use of Ajax pass parameters to implement validation:
1, directly in the form form submit button implementation verification, in the controller VerifyController.class.php write the following code:
Namespace Home\controller;use Think\controller;class Verifycontroller extends Controller {public function index () { $this->display (); } Public Function Checklogin () { $verify =new \think\verify (); $code =i (' post.verify ');//The form Verification code if ($verify->check ($code)) { $this->success (' captcha correct '); } else{ $this->error (' Verification Code error '); } } Public Function Verify () { //Instantiate Verify object $verify = new \think\verify (); Configure the CAPTCHA parameter $verify->fontsize = +; Captcha Font size $verify->length = 4; Verify the number of code digits $verify->imageh =; Verification code Height $verify->useimgbg = true; Turn on the captcha background $verify->usenoise = false; Turn off captcha noise $verify->entry ();} }
The code in view verify/index.html is as follows:
<! DOCTYPE html>
2, using the Ajax pass parameter implementation validation, the code in the controller VerifyController.class.php is as follows:
Namespace Home\controller;use Think\controller;class Verifycontroller extends Controller {public function index () { $this->display (); } Public Function Checklogin () { $verify =new \think\verify (); $code =$_post[' code '];//ajax verification code get if ($verify->check ($code)) { $this->ajaxreturn (1); } else{ $this->ajaxreturn (0); } } Public Function Verify () { //Instantiate Verify object $verify = new \think\verify (); Configure the CAPTCHA parameter $verify->fontsize = +; Captcha Font size $verify->length = 4; Verify the number of code digits $verify->imageh =; Verification code Height $verify->useimgbg = true; Turn on the captcha background $verify->usenoise = false; Turn off captcha noise $verify->entry ();} }
The code in view verify/index.html is as follows:
<! DOCTYPE html>In the 2nd method, do not forget to download the Jquery.min.js file: http://www.jq22.com/jquery-info122
To configure the address in profile common/conf/config.php:
return Array (/ * Address replace * /' tmpl_parse_string ' =>array ( ' __js__ ' =>__root__. /public/js ', ),);
Implementation of thinkphp Verification code