Home > Backend Development > PHP Tutorial > Implementation method of adding verification code in yii2

Implementation method of adding verification code in yii2

WBOY
Release: 2016-07-29 09:07:13
Original
1115 people have browsed it

The example in this article describes the implementation method of adding verification code in yii2. Share it with everyone for your reference, as follows:

First, add the verification code field in the model:

public function rules(){
return ['verifyCode', 'captcha'],
}

Copy after login

Secondly, you can add the field name of the verification code in the front page in the function attributeLabels:

public function atrributeLabels(){
return ['verifyCode'=>'Verification Code', ];
}

Copy after login

Then , make the following modifications in the view file:

use yii\captcha\Captcha;
<&#63;= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
          'template' => '<div><div>{image}</div><div>{input}</div></div>',
 ]) ?>

Copy after login

I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.

The above introduces the implementation method of adding verification code in yii2, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template