我正在使用 yii2 高级框架的默认验证码实现。我有一个问题:我想在验证码中添加刷新按钮,但我不知道该怎么做
最佳答案
将验证码操作添加到您的 Controller ,将验证码添加到您的表单,将验证码
的字段和验证规则添加到您的模型。了解更多 here .
并在 View 中添加按钮以更新验证码图像,如下所示:
<?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');
})
"); ?>
关于php - Yii2 验证码刷新按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38027879/