I am using the default captcha implementation of the yii2 advanced framework. I have a problem: I want to add a refresh button to my captcha but I do not know how can I do it
Add captcha action to your controller, add captcha to your form, add field and validate rules for captcha to your model. Read more here.
And add button in view for update captcha image, like this:
<?php echo $form->field($model, 'captcha')->widget(Captcha::className(), [
'imageOptions' => [
'id' => 'my-captcha-image'
]
]); ?>
<?php echo Html::button('Refresh captcha', ['id' => 'refresh-captcha']);?>
<?php $this->registerJs("
$('#refresh-captcha').on('click', function(e){
e.preventDefault();
$('#my-captcha-image').yiiCaptcha('refresh');
})
"); ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With