Hi folks,
I have a little problem with using a captcha to verify the data within a model based on an ActiveRecord.
Do I have to do something else or in addition, like I would do when using an model based on a CFormModel?
What I have done is: declaring a public variable $verifyCode within my ActiveRecord, inserting a rule to verify that the given text is the same like in the captcha:
class Subscriber extends CActiveRecord
{
....
public $verifyCode;
....
public function rules()
{
return array(
...
array('verifyCode', 'captcha', 'allowEmpty'=>!extension_loaded('gd')),
);
}
...
public function attributeLabels()
{
return array(
'verifyCode'=>'Verification Code',
...
);
}
}
overwriting the action method in my controller:
class SiteController extends CController
{
public function actions()
{
return array(
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xEBF4FB,
),
);
}
..
}
and inserting the widget into the formView:
...
<?php if(extension_loaded('gd')): ?>
<div class="simple">
<?php echo CHtml::activeLabel($model,'verifyCode'); ?>
<div>
<?php $this->widget('CCaptcha'); ?>
<?php echo CHtml::activeTextField($model,'verifyCode'); ?>
</div>
<p class="hint">Bitte gib die Buchstaben so ein wie du sie im Bild siehst.
<br/>Buchstaben sind nicht Case-Sensitive.</p>
</div>
<?php endif; ?>
...
All the times I submit this form, the validation says that the code is not right.
If I’ve understand the whole thing in the right way, this should work, or not?
Do the validation in the active record depends on a column in my db or something like this? Did I forgot something else?
Would be nice if someone could help me out with this.
regards,
- mageta