6

I have a user registration form, in which I am trying to display a Captcha image by using Yii widget CCaptcha, however my image link appears broken, Controller file:

public function actions()
    {
        return array(
            // captcha action renders the CAPTCHA image displayed on the contact page
            'captcha'=>array(
                'class'=>'CCaptchaAction',
                'backColor'=>0xFFFFFF,
            ),
        );
    } 

Model File:

public function rules()
 {
    return array( array('verifyCode','captcha','allowEmpty'=>!CCaptcha::checkRequirements(),'on'=>'insert'), 
);
}

And view file:

<?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 shown.
        <br/>Letters are not case-sensitive.</div>
        <?php echo $form->error($model,'verifyCode'); ?>
    </div>
    <?php endif; ?>

As a answer provided somewhere I also tried giving the access rules in my controller file as

public function accessRules()
{
    return array(
        array('allow',
         'actions' => array('captcha'), 
         'users' => array('*'),
         ),
    );
}

But nothing seems to be working.

dibs_ab
  • 723
  • 2
  • 13
  • 24
  • I tested your code and there was no error! Just I add this 'on'=>'insert' but appeared the image of the captcha! – SoldierCorp Aug 10 '12 at 04:35
  • I have written the 'on'=>'insert' too in my model class. but no luck there. The yiic tool generated app's captcha is visible which means, there's something, I'm missing or writing incorrectly. – dibs_ab Aug 10 '12 at 05:46

2 Answers2

8

The problem was with the controller file,it should have been,

public function accessRules()
    {
        return array(
            array('allow', 
                'actions'=>array('create', 'captcha'),
                'users'=>array('*'),
            ),
    } 


whereas I had mentioned the action for captcha at the end, which I figured out is not allowed in Yii. All the allow actions for * should be together.

dibs_ab
  • 723
  • 2
  • 13
  • 24
-1

Yii captcha will create a png image. A possible explanation for the broken image link would be a missing GD extension or imagick extension, which can be identified by the presence of the following text in your error.log:

call to undefined function imagecreatetruecolor

For details and fix see "call to undefined function imagecreatetruecolor" error in PHP & pChart

Community
  • 1
  • 1
Manh
  • 1
  • 2