【问题标题】:Yii Captcha does not show refresh buttonYii Captcha 不显示刷新按钮
【发布时间】:2014-03-12 10:52:42
【问题描述】:

我有一个 应用程序,我使用主题来管理不同的样式和布局。在默认生成的contact.php中,我使用以下代码为表单生成验证码:

    //webroot/themes/botany/views/site/contact.php
    <?php //echo $form->labelEx($model,'verifyCode'); ?>
            <div>
            <?php $this->widget('CCaptcha', array('showRefreshButton' => true,
'buttonLabel' => 'Refresh', 
'buttonOptions' => '', 
'buttonType' => 'button',
 'clickableImage' => true)); 
?>
            <?php echo $form->textField($model,'verifyCode', array('class' => 'form-control', 'placeholder' => 'Captcha*')); ?>
            </div>
            <p>Please enter the letters as they are shown in the image above.
            <br/>Letters are not case-sensitive.</p>
            <?php echo $form->error($model,'verifyCode'); ?>

        <?php endif; ?>

虽然我设置了showRefreshButton =&gt; true,但我看不到刷新按钮。以下屏幕截图演示了没有刷新按钮:

【问题讨论】:

    标签: yii yii captcha


    【解决方案1】:

    经过一番检查,我发现,我认为是 Yii 中的一个错误,其中不同的小部件生成具有相同 id 的 HTML 元素。

    在我的情况下,webroot/themes/botany/views/layouts/main.php 中的 zii.widgets.CMenu 小部件为导航菜单的 ul 生成相同的 id,而 Captcha 小部件图像被验证码小部件生成的 jquery 视为 id。

    我可以通过提供 CMenu 的 id 选项来解决这个问题

    <?php $this->widget('zii.widgets.CMenu',array(
                                        'id' => 'gds',
                'htmlOptions' => array('class' => 'nav'),
                'items'=>array(
                    array('label'=>'Home', 'url'=>array('/site/index')),
                    array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),
                    array('label'=>'Contact', 'url'=>array('/site/contact')),
                    array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
                    array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)
                ),
    
            )); ?>
    

    并为验证码图像设置yw0 id。

    <?php $this->widget('CCaptcha', array('imageOptions' => array('id' => 'yw0'),'showRefreshButton' => true,'buttonLabel' => 'Refresh', 'buttonOptions' => '', 'buttonType' => 'button')); ?>
    

    【讨论】:

      【解决方案2】:

      你使用了什么类型的渲染函数?如果您使用的是 renderPartial,它不会显示刷新按钮。简单的方法是创建一个新的空白布局并使用 render() http://www.dukaweb.net/2013/12/why-does-yii-captcha-not-display-get.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-05-29
        • 1970-01-01
        • 2011-06-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-10
        相关资源
        最近更新 更多