hi, I am newbie in the Yii framework. now I am having trouble.
I make registration form but can’t display captcha image.
Biodata.php model code
<?php
class Biodata extends CActiveRecord
{
public $verifyCode;
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('nama,alamat,hp,email,program_profesi,verifyCode','required'),
array('idprogram_studi, tahun_lulus', 'numerical', 'integerOnly'=>true),
array('tgl_lahir', 'safe'),
array('email','email'),
array('verifyCode', 'captcha', 'allowEmpty'=>!extension_loaded('gd'),'on'=>'add'),
// MUST BE AFTER ABOVE LINE:
// array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
);
}
code on view add.php
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'biodata-form',
'enableAjaxValidation'=>true,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
...........
<?php if(extension_loaded('gd')): ?>
<div class="row">
<?php echo $form->labelEx($model,'verifyCode'); ?>
<div>
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->textField($model,'verifyCode'); ?>
</div>
<div class="hint">Silahkan masukan Please enter the letters as they are shown in the image above.
<br/>Letters are not case-sensitive.</div>
</div>
<?php endif; ?>
........
<?php
class BiodataController extends Controller
{
/**
* @var string the default layout for the views. Defaults to '//layouts/column2', meaning
* using two-column layout. See 'protected/views/layouts/column2.php'.
*/
public $layout='//layouts/column2';
/**
* @return array action filters
*/
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
);
}
987
I’ve tried copying the captcha that’s in contact form, but still not running. if the captcha is not able to walk in CActiveForm?