如何为Yii2 Captcha小部件设置标签?

时间:2016-01-29 08:19:50

标签: php yii2

使用Yii2,我意识到CAPTCHA Widget的模板属性只有{image}{input}令牌。我的问题是,我如何通过模板属性实际设置{label}令牌并移动它,所以我想在{image}之下想要它?

我尝试过以下操作:(在field内设置标签,就像普通表格字段一样。)

<?= $form->field($model, 'verifyCode', ['template' => '{label}'])->widget(Captcha::className(), [
    'template' => '<div class="col-xs-12">{image}</div><div class="col-xs-12">{input}</div>',
    'options' => ['placeholder' => 'CAPTCHA Code', 'class' => 'form-control']
]) ?>

谢谢!

1 个答案:

答案 0 :(得分:-1)

<?= $form->field($model, 'captcha')->widget(\yii\captcha\Captcha::classname(),['options' => [
                     'placeholder' => 'Please enter the letters displayed above'
                        , 'Class' => 'form-control'
                        , 'style' => 'Top-margin: 10px;'
                ]])->label('Security Code')?>