1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/zhyun-GACaptcha

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
CaptchaWidget.php 1.6 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
东城影 Отправлено 14.03.2017 04:40 6c116c6
<?php
/**
* Created by PhpStorm.
* User: xin
* Date: 16/12/22
* Time: 下午2:25
*/
namespace ga\captcha;
use yii\widgets\InputWidget;
use yii\helpers\Html;
use yii\helpers\Url;
class CaptchaWidget extends InputWidget
{
public $captchaAction = 'site/captcha';
public $template = '{input}{image}';
public $imageOptions;
private $imageID = 'ga-captcha';
public function run()
{
$this->reloadID();
$this->registerJS();
if ($this->hasModel()) {
$input = Html::activeTextInput($this->model, $this->attribute, $this->options);
} else {
$input = Html::textInput($this->name, $this->value, $this->options);
}
$route = Url::toRoute($this->captchaAction);
$image = Html::img($route, $this->imageOptions);
echo strtr($this->template, [
'{input}' => $input,
'{image}' => "<a href='#'>$image</a>",
]);
}
protected function reloadID()
{
if (empty($this->imageOptions)) {
$this->imageOptions['id'] = $this->imageID;
} else {
$this->imageID = $this->imageOptions['id'];
}
}
protected function registerJS()
{
$js = <<<JS
jQuery(window).ready(function(){
var dom = jQuery('#$this->imageID');
var id = 1;
dom.click(function(){
dom.attr('src', '/' + '$this->captchaAction' + '?id=' + id);
id++;
});
});
JS;
$this->getView()->registerJs($js);
return $js;
}
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/zhyun-GACaptcha.git
git@api.gitlife.ru:oschina-mirror/zhyun-GACaptcha.git
oschina-mirror
zhyun-GACaptcha
zhyun-GACaptcha
master