代码拉取完成,页面将自动刷新
composer require ga/captcha dev-master
1.Set up following code in actions
method of SiteController
.(Default)
You can also change the "url" route what you want, but you should change the captchaAction
property for CaptchaWidget in the next step.
Class SiteController extend yii\web\Controller
public function actions()
{
return [
'captcha'=>[
'class' => 'ga\captcha\CaptchaAction',
]
];
}
2.Create Widget
in the view file, and it's support the active mode.
<?php
use app\models\CaptchaWidget;
use yii\helpers\Html;
?>
<?= Html::beginForm('site/test', 'post')?>
<?= CaptchaWidget::widget([
'name' => 'captcha',
'template' => '<label for="captcha">Captcha</label>  {input}{image}',
'options' => ['id' => 'captcha'],
]);?>
<?= Html::submitButton('Submit')?>
<?= Html::endForm()?>
NOTE: If you change the url route, and you need to set the captchaAction
property.
<?= CaptchaWidget::widget([
...,
'captchaAction'=> 'controller/action'
]);?>
3.Config your method need to validate the verification code.
public function actionTest(){
$res = Yii::$app->request->post('captcha');
$ca = new CaptchaValidator();
if($ca->validate($res)){
echo "success";
}else{
echo "fail";
}
}
Thanks for the author of HansKendrickV-Regular.ttf
to provide the nice free font.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型