CCaptcha

Hey Guys,

could anyone tell me whats wrong here? I tried to use the CCaptcha for the Comment part of the Blog tutorial,

but the Image is not Visible.

some Code:

Model:

comment.php





class comment extends CActiveRecord

{

	/*

	 * const vars

	 */

	const STATUS_PENDING = 0;

	const STATUS_APPROVED = 1;

	

	public $verifyCode;

	/**

	 * The followings are the available columns in table 'comment':

	 * @var integer $Id

	 * @var integer $postId

	 * @var integer $authorId

	 * @var string $title

	 * @var string $content

	 * @var integer $creationTime

	 * @var string $email

	 * @var string $url

	 * @var integer $status

	 */

	

	/**

	 * Returns the static model of the specified AR class.

	 * @return CActiveRecord the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'comment';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		return array(

			array('title','length','max'=>255),

			array('email','length','max'=>255),

			array('url','length','max'=>255),

			array('content, email', 'required'),

			array('creationTime, status', 'numerical', 'integerOnly'=>true),

			array('verifyCode', 'captcha', 'on'=>'insert',

				'allowEmpty'=>!Yii::app()->user->isGuest),

		);

	}


	public function safeAttributes()

	{

		return array('email', 'title', 'url', 'content', 'verifyCode');

	}




Comment form:

[html]

<div class="yiiForm">

<p>

<b>Leave a Comment!</b> (Fields with <span class="required">*</span> are required.)

</p>

<?php if(Yii::app()->user->hasFlash(‘commentSubmitted’)): ?>

&lt;div class=&quot;confirmation&quot;&gt;


	&lt;?php echo Yii::app()-&gt;user-&gt;getFlash('commentSubmitted'); ?&gt;


&lt;/div&gt;

<?php endif; ?>

<?php echo CHtml::beginForm(); ?>

<?php echo CHtml::errorSummary($comment); ?>

<div class="simple">

&lt;?php echo CHtml::activeLabelEx(&#036;comment,'email'); ?&gt;


&lt;?php echo CHtml::activeTextField(&#036;comment,'email',array('size'=&gt;40,'maxlength'=&gt;255)); ?&gt;

</div>

<div class="simple">

&lt;?php echo CHtml::activeLabelEx(&#036;comment,'url'); ?&gt;


&lt;?php echo CHtml::activeTextField(&#036;comment,'url',array('size'=&gt;40,'maxlength'=&gt;255)); ?&gt;

</div>

<div class="simple">

&lt;?php echo CHtml::activeLabelEx(&#036;comment,'title'); ?&gt;


&lt;?php echo CHtml::activeTextField(&#036;comment,'title',array('size'=&gt;40,'maxlength'=&gt;255)); ?&gt;

</div>

<div class="simple">

&lt;?php echo CHtml::activeLabelEx(&#036;comment,'content'); ?&gt;


&lt;?php echo CHtml::activeTextArea(&#036;comment,'content',array('rows'=&gt;6, 'cols'=&gt;50)); ?&gt;

</div>

<?php if(extension_loaded(‘gd’)): ?>

&lt;div class=&quot;simple&quot;&gt;


	&lt;?php echo CHtml::activeLabel(&#036;comment,'verifyCode'); ?&gt;


	&lt;div&gt;


	&lt;?php &#036;this-&gt;widget('CCaptcha'); ?&gt;


	&lt;?php echo CHtml::activeTextField(&#036;comment,'verifyCode'); ?&gt;


	&lt;/div&gt;


	&lt;p class=&quot;hint&quot;&gt;Please enter the letters as they are shown in the image above.


	&lt;br/&gt;Letters are not case-sensitive.&lt;/p&gt;


&lt;/div&gt;

<?php endif; ?>

<div class="action">

<?php echo CHtml::submitButton($update ? ‘Save’ : ‘Create’, array(‘name’=>‘submitComment’)); ?> <?php echo CHtml::submitButton(‘Preview’,array(‘name’=>‘previewComment’)); ?>

</div>

<?php echo CHtml::endForm(); ?>

[/html]

and CommentController:





/**

	 * Declares class-based actions.

	 */

	public function actions()

	{

		return array(

			// captcha action renders the CAPTCHA image

			// this is used by the contact page

			'captcha'=>array(

				'class'=>'CCaptchaAction',

				'backColor'=>0xB7DDF2,

			),

		);

	}




Did anyone have an Idea whats wrong? I dont see any Issues there :(

Regards,

sebi

Okay, I know what is wrong, the html shows me that the Captcha refers to:

<img id="yw0" src="/blog/index.php?r=post/captcha" alt="" />

instead of r=comment/captcha

did anyone know how to fix it, or how I can set the right controller/action for the captcha?

The Comment form is shown via

<?php $this->renderPartial(’/comment/_form’, array(

	'comment' =&gt; &#036;newComment,


	'update' =&gt; false,


)); ?&gt;

and the Captcha is in /comment/_form which is posted above.

Not sure…however, have you already enabled gd extension?

yes gd ext is working fine.

Edit:

Solved the issue ->

array(‘allow’, // allow all users to perform ‘list’ and ‘show’ actions

			'actions'=&gt;array('list','show', 'captcha'),


			'users'=&gt;array('*'),


		),

you need to allow the ‘captcha’ action in the specified Controller:

@qiang: this should be more clarified in the blog tutorial, it could be a very deep

hole for newbies ;)

Regards,

sebi