0

I have just realized that my captcha doesn't display the images, is like if it was broke. I'm sure that before it works well, but I don't know what happened.

So, the first thing that I did was to change the model, view and controller edited for my for the original created using Yii, but now it dosen't work either...

Now I have the following controller (the originals created by Yii):

<?php

class SiteController extends Controller
{
/**
 * Declares class-based actions.
 */
public function actions()
{
    return array(
        // captcha action renders the CAPTCHA image displayed on the contact page
        'captcha'=>array(
            'class'=>'CCaptchaAction',
            'backColor'=>0xFFFFFF,
        ),
        // page action renders "static" pages stored under 'protected/views/site/pages'
        // They can be accessed via: index.php?r=site/page&view=FileName
        'page'=>array(
            'class'=>'CViewAction',
        ),
    );
}

    ...

The model:

<?php

/**
 * ContactForm class.
 * ContactForm is the data structure for keeping
 * contact form data. It is used by the 'contact' action of 'SiteController'.
*/
class ContactForm2 extends CFormModel
{
public $name;
public $email;
public $subject;
public $body;
public $verifyCode;

/**
 * Declares the validation rules.
 */

public function rules()
{
    return array(
        // name, email, subject and body are required
        array('name, email, subject, body', 'required'),
        // email has to be a valid email address
        array('email', 'email'),
        // verifyCode needs to be entered correctly
        array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
    );
}

...

and the 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; ?>

     ...

I think that my problem may be like the reported in the following link, so I also used the follow accessRules()

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

and

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

But both gave me errors:

"ContactForm2 tiene una regla de validación inválida. La regla se debe especificar attributos para ser validados y el nombre de su validador."

Please, someone could help me? Why is happening this? I read a lot about this topic, but I didn't find the solution...

Community
  • 1
  • 1
franki
  • 23
  • 6
  • check this forum: http://www.yiiframework.com/forum/index.php/topic/20087-captcha-validator-dont-work-properly/ – Kumar V Feb 13 '14 at 11:32
  • @kumar_v thanks, I also searched for there, but I didn't find anything :( – franki Feb 13 '14 at 11:38
  • did you set `'testLimit' => 2,`? – Kumar V Feb 13 '14 at 11:39
  • @Kumar_v I don't understand you, could explain what are you reffering to me? – franki Feb 13 '14 at 11:47
  • You didn't check my link. That's why you didn't understand. – Kumar V Feb 13 '14 at 11:48
  • @kumar_v thanks. I read your link, and I understood that ours problems were different, since I don't have any problem with the validation, my problem is that I can't see the captcha image. Even so, I tried what you said ('testLimit' => 2) but it doesn't work. – franki Feb 13 '14 at 11:54
  • check the error in firebug. What exactly is the error? is it "not found" or "permission denied". Also, accessRules is different from rules. The one used in controller is accessRules – sadaf Feb 13 '14 at 12:57
  • @franki It is a validation problem: "[...] regla de validación inválida [...]". Please show as the full log of errors. – Jorge Barata Feb 13 '14 at 12:57
  • 1
    @sadaf and and Jorge B.G thanks. I'm sorry to reply so late. In the end, I could fixed the bug, I had the caracters "?>" at the end of one of files that I uploaded recently. When I removed these caracters the captcha was displayed again. – franki Feb 20 '14 at 11:17

0 Answers0