Request Widget From Other Conroller Than The View (Captcha Via Renderpartial)

Edit: after some trouble with the spamfilter (about the word ’ v a l i d a t i n g’) I did succeed to post the complete question.

Hope someone can help

=========

Hi there,

I’m desperate what to do next because of - what I think is - a simple mistake. So I hope someone can help me.

I have a guestion about using captcha via renderPartial. I want to render a form from the the model Feedback on my frontpage, so in //site/index I:


echo $this->renderPartial('//feedback/_frontpage_form',

			array(	'model'		=>	new Feedback('insert'),    

				), true, true);

The problem is that in the way I tried I need twice the code:


public function actions()

	{

		return array(

			// captcha action renders the CAPTCHA image displayed on the contact page

			'captcha'=>array(

				'class'=>'CCaptchaAction',

				'backColor'=>0xFFFFFF,

				

			),

		);

Once in the SiteController and once in FeedbackController.

When I leave out the code in SiteController I don’t get the image, because index/site/capthca?v=. does not exists. When I leave out the code in the feedback controller, I retrieve the error when posting:


CCaptchaValidator.action captcha is invalid. Cannot find a comparable action in current controller

I figured out that this is probably because I use:


echo '<div class="row">'.

				$form->labelEx($model,'verifyCode');

				[b]$this->widget('CCaptcha');[/b]

		echo $form->textField($model,'verifyCode') . 

			'</div>' .

			'<div class="hint">Type aub het bovenstaande woord over.</div>'.

			$form->error($model,'verifyCode');

$this->widget in the renderPartial view, and the $this is related to the SiteController, but I can not figure out how I can print a widget from another controller.

Is this a familiar problem for others and can you please help me with this problem?

Thank you so much in advance!

Reinier

Hi FOX, welcome to the forum.

You can try to set "captchaAction" property of CCaptcha explicitly.

It defaults to "captcha" action of the current controller.

http://www.yiiframework.com/doc/api/1.1/CCaptcha#captchaAction-detail

But, personally I think there’s not so big a problem in repeating captcha actions in different controllers, because you can use a class based action of CCaptchaAction.

Hi Softark!

Thanks for your quick reply! I could not react earlier because of the limit of three posts for the first day. But thanks ;)

Adding the captchaAction to the widget made my day.

Topic can be closed.

Reinier

Hi Reinier,

Glad to hear that. :)

BTW, you don’t have to close your topic, because someone else in the future will want to add some interesting question and/or useful tip regarding this.