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...