PHP Класс yii\captcha\Captcha
Captcha is used together with
CaptchaAction to provide
CAPTCHA - a way
of preventing website spamming.
The image element rendered by Captcha will display a CAPTCHA image generated by
an action whose route is specified by [[captchaAction]]. This action must be an instance of
CaptchaAction.
When the user clicks on the CAPTCHA image, it will cause the CAPTCHA image
to be refreshed with a new CAPTCHA.
You may use
CaptchaValidator to validate the user input matches
the current CAPTCHA verification code.
The following example shows how to use this widget with a model attribute:
php
echo Captcha::widget([
'model' => $model,
'attribute' => 'captcha',
]);
The following example will use the name property instead:
php
echo Captcha::widget([
'name' => 'captcha',
]);
You can also use this widget in an [[\yii\widgets\ActiveForm|ActiveForm]] using the [[\yii\widgets\ActiveField::widget()|widget()]]
method, for example like this:
php
field($model, 'captcha')->widget(\yii\captcha\Captcha::classname(), [
configure additional widget properties here
]) ?>
Показать файл
Открыть проект
Примеры использования класса
Открытые свойства
Свойство |
Тип |
Описание |
|
$captchaAction |
|
the route of the action that generates the CAPTCHA images.
The action represented by this route must be an action of CaptchaAction.
Please refer to [[\yii\helpers\Url::toRoute()]] for acceptable formats. |
|
$imageOptions |
|
HTML attributes to be applied to the CAPTCHA image tag. |
|
$options |
|
the HTML attributes for the input tag. |
|
$template |
|
the template for arranging the CAPTCHA image tag and the text input tag.
In this template, the token {image} will be replaced with the actual image tag,
while {input} will be replaced with the text input tag. |
|
Открытые методы
Защищенные методы
Описание методов
checkRequirements()
публичный статический метод
This method will check the existence of ImageMagick and GD extensions.
getClientOptions()
защищенный метод
Returns the options for the captcha JS widget.
registerClientScript()
публичный метод
Registers the needed JavaScript.
Описание свойств
$captchaAction публичное свойство
the route of the action that generates the CAPTCHA images.
The action represented by this route must be an action of
CaptchaAction.
Please refer to [[\yii\helpers\Url::toRoute()]] for acceptable formats.
$imageOptions публичное свойство
HTML attributes to be applied to the CAPTCHA image tag.
$options публичное свойство
the HTML attributes for the input tag.
$template публичное свойство
the template for arranging the CAPTCHA image tag and the text input tag.
In this template, the token {image} will be replaced with the actual image tag,
while {input} will be replaced with the text input tag.