H
H
happ2016-08-05 14:15:08
Yii
happ, 2016-08-05 14:15:08

How to update captcha on image click in yii2?

I'm trying to implement a captcha update on click, but I don't know which way to dig.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nepster-web, 2016-08-05
@happ

yiiframework.ru/forum/viewtopic.php?t=23789

H
happ, 2016-08-05
@happ

Maybe someone will come in handy.
js:
We hang on the image container (you can immediately on the image).
And the request is sent to the route and the action responsible for generating the captcha.
/*refresh captcha*/
$('.captcha_container img').click(function(e) {
alert('hello');
$.ajax({
type: 'GET',
url: '/site/captcha',
data : {refresh: 1},
dataType: 'json',
success: function (data) {
$(".captcha_container img").attr('src', data.url);
}
});
});
view:
<?= $form->field($comment, 'verifyCode')->widget(Captcha::
'template' => '{image}{input}',
]) ?>
model:
public function rules() {
/*input email is email*/
return [
[['post_id', 'author', 'message', 'email'], 'required', 'on' => self::SCENARIO_SAVE],
['email', 'email'],
'captcha' => ['verifyCode', 'captcha','captchaAction'=>' site/captcha'],
];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question