php - Yii2 验证码刷新按钮

标签 php yii yii2 yii2-advanced-app

我正在使用 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/

相关文章:

php - mysql 到 csv 格式不正确

php - Yii - 模型和 Controller 之间的界限 - 什么方法在哪里? MVC原则

php - Yii 1.1 与 PHP 5.6 : how to skip Redis connection error silently

yii2 - 错误请求 (#400) - 缺少必需参数 : id in YII2

PHP range() 从 A 到 ZZ?

PHP 错误 : The Encrypt library requires the Mcrypt extension in codeigniter

javascript - 从树形结构数据库生成 JSON

Yii2:从登录使用漂亮的 url 重定向时的路径问题

error-handling - Yii2,模块错误页面不显示,但在错误 404 时显示空白页面

PHP/HTML 表单的下拉菜单不显示已填写的属性