micz
(Micz84)
March 30, 2010, 1:06pm
1
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?
kenz
(Kenneth Soderlund)
March 31, 2010, 12:56pm
2
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?
Hi,
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:
…
‘model’=>$userModel,
‘type’=>‘form’
…
mintao
(Florian Fackler)
May 1, 2010, 9:07pm
3
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”
<?php
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,
),
Yii::app()->controller->widget('CCaptcha'),
'capatcha' => array(
'label' => Yii::t('form', 'Insert verification code'),
'type' => 'text',
),
),
'buttons' => array(
'submit' => array(
'type' => 'submit',
'label' => Yii::t('form', 'submit'),
),
),
);
kenz
(Kenneth Soderlund)
May 3, 2010, 6:10am
4
mintao:
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”
<?php
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,
),
Yii::app()->controller->widget('CCaptcha'),
'capatcha' => array(
'label' => Yii::t('form', 'Insert verification code'),
'type' => 'text',
),
),
'buttons' => array(
'submit' => array(
'type' => 'submit',
'label' => Yii::t('form', 'submit'),
),
),
);
Hi!
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:
ob_start();
$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(
'title'=>'Verification',
$image,
array(
'name'=>'verifyCode',
'type'=>'text',
)
);
Hope this helps!
Eliovir
(Eliovir)
May 31, 2010, 2:53pm
5
I encountered the same clue this afternoon and posted that:
With Yii-1.1.2, you can solve your problem with
Yii::app()->controller->widget("CCaptcha", array(), true);