首先,在模型中添加验证码字段:
public function rules(){
return [‘verifyCode‘, ‘captcha‘],
}
其次,可以在函数attributeLabels中添加前台页面中验证码的字段名称:
public function atrributeLabels(){
return [‘verifyCode‘=>‘Verification Code‘, ];
}
然后,在视图文件中做如下修改:
use yii\captcha\Captcha;
<?= $form->field($model, ‘verifyCode‘)->widget(Captcha::className(), [
‘template‘ => ‘<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>‘,
]) ?>
时间: 2024-10-06 13:27:45