Problem with ActiveRecord and CForm

I have created User model with additional fields for captcha and password repeat. I have added rules for them and I have added them to ‘register’ scenario. I have created CForm configuration file for registration form, but it do not show fields for register scenario. What should I do to tell CForm that it is register scenario?


When you create the new user, you can give the scenario as a parameter:

$userModel = new User('register');

Then in the form configuration you can use:



Could you please tell me, how you inserted the CCaptcha widget into the form? I’m using the form builder, but had no luck :( Here’s my first try - missing input field for captcha string, I know ;) but this thing throws an exception “Object of class CCaptcha could not be converted to string”


return array(

    'elements' => array(

        'name' => array(

            'type' => 'text',

            'class' => 'span-6',


        'email' => array(

            'type' => 'text',

            'class' => 'span-6',


        'body' => array(

            'type' => 'textarea',

            'class' => 'span-6',

            'cols' => 50,

            'rows' => 10,



        'capatcha' => array(

            'label' => Yii::t('form', 'Insert verification code'),

            'type' => 'text',




    'buttons' => array(

        'submit' => array(

            'type' => 'submit',

            'label' => Yii::t('form', 'submit'),





I had the same problem with the captcha image, but there is a solution for it. May not be the nicest solution, but it still works.

I have a function in the controller, just like the sitecontroller in the main code:

public function actions()


  return array('captcha'=>array('class'=>'CCaptchaAction'));


And then in the form builder I just create the captcha image:


$this->widget('CCaptcha', array('captchaAction'=>#url to the captcha action);

$image = ob_get_clean();

Then I can use the image in the form builder:

return array(








Hope this helps!

I encountered the same clue this afternoon and posted that:

follow this wiki -