Reputation: 1073
I have applied all other solutions here regarding broken yii captcha but to no avail. So I'm adding my own question.
I have gone through the yii blog tutorial (http://www.yiiframework.com/doc/blog/) but rather than having comments approved, I want to have a captcha in the comment form. I have added this to comment form view:
<?php if(CCaptcha::checkRequirements()): ?>
<div class="row">
<?php echo $form->labelEx($model,'verifyCode'); ?>
<div>
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->textField($model,'verifyCode'); ?>
</div>
<div class="hint">Please enter the letters as they are shown in the image above.
<br/>Letters are not case-sensitive.</div>
<?php echo $form->error($model,'verifyCode'); ?>
</div>
<?php endif; ?>
And in CommentController, accessRules() becomes:
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view', 'captcha'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
And I override actions() in CommentController:
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xD99D25,
),
);
}
To the Comment model, I have added a new rule:
array('verifyCode', 'captcha', 'on' => 'insert', 'allowEmpty'=>!Yii::app()->user->isGuest)
and new public member:
public $verifyCode;
The captcha on contact form works fine. But in the comment form, the image is broken and the link to refresh it does not work. Any ideas?
Upvotes: 1
Views: 1116
Reputation: 1912
I added this code into the blog demo and it looks like the request for the captcha is going to PostController not CommentController. If you add the captcha action to PostController instead it should work.
Upvotes: 1
Reputation: 979
Have you opened your firebug or web inspector? What response it gives you on captcha request?
Upvotes: 0