Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
systems:yii2:email_tools [2018/05/10 16:50]
smayr [Setup Captcha]
systems:yii2:email_tools [2018/05/14 11:08] (current)
smayr [Setup Captcha]
Line 146: Line 146:
                 <?= $form->field($model, 'subject') ?>                 <?= $form->field($model, 'subject') ?>
                 <?= $form->field($model, 'body')->textArea(['rows' => 6]) ?>                 <?= $form->field($model, 'body')->textArea(['rows' => 6]) ?>
-                <!-- // To regenerate new captcha after each refresh, call getVerifyCode().  +                 
-                     // See: http://www.yiiframework.com/forum/index.php/topic/17638-captcha-code-not-changing +                <?php  
-                 --> +                    // To regenerate new captcha after each refresh, call getVerifyCode().  
-                <?php $this->context->createAction('captcha')->getVerifyCode(true) ?>+                    // See: http://www.yiiframework.com/forum/index.php/topic/17638-captcha-code-not-changing 
 +                    $this->context->createAction('captcha')->getVerifyCode(true)
 +                ?>
                 <?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [                 <?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
                     'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',                     'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
Line 442: Line 444:
  
 == Setup Captcha == == Setup Captcha ==
 +
 +''CaptchaAction'' requires either GD2 extension or ImageMagick PHP extension. Check that it meets this requirement.
  
 In controller's function ''behaviors()'', add ''captcha'' to ''actions'' for user group that requires the use ot if: In controller's function ''behaviors()'', add ''captcha'' to ''actions'' for user group that requires the use ot if:
Line 539: Line 543:
 </code> </code>
  
-In form view using the captcha, add ''verifyCode'' entry to the ''rules()'' function:+In form view using the captcha, add ''verifyCode'' field:
 <code php> <code php>
 +<?php 
 +   // To regenerate new captcha after each refresh, call getVerifyCode(). 
 +   // See: http://www.yiiframework.com/forum/index.php/topic/17638-captcha-code-not-changing/.
 +   $this->context->createAction('captcha')->getVerifyCode(true); 
 +?>
 +<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
 +     'captchaAction' => 'site/captcha',  // redirect to correct controller where captcha is defined
 +     'template'      => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
 +]) ?>
 </code> </code>
 +
 +See more:
 +  * [[https://www.yiiframework.com/doc/api/2.0/yii-captcha-captchaaction|Yii CaptchaAction]]