captcha, Image not show

hi yii’ers i want to ask about the captcha. why the captcha image is not visible. I’ve tried most of which exist in the forum but have not succeeded.

this my code

view




	<?php if(CCaptcha::checkRequirements()): ?>

	<div class="row">

		<?php echo $form->labelEx($model,'verifyCode'); ?>

		<div>

		<?php $this->widget('CCaptcha'); ?>

		<?php echo $form->textField($model,'verifyCode'); ?>

		</div>

		<div class="hint">Please enter the letters as they are shown in the image above.

		<br/>Letters are not case-sensitive.</div>

	</div>

	<?php endif; ?>



models




	public function rules()

	{

		return array(

			// name, email, subject and body are required

			array('name, email, subject, body', 'required'),

			// email has to be a valid email address

			array('email', 'email'),

			// verifyCode needs to be entered correctly

			array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),

		);

	}



controller




public function actions()

	{

		return array(

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

			'captcha'=>array(

				'class'=>'CCaptchaAction',

				'backColor'=>0xFFFFFF,

				'testLimit'=>3,

			),

			// page action renders "static" pages stored under 'protected/views/site/pages'

			// They can be accessed via: index.php?r=site/page&view=FileName

			'page'=>array(

				'class'=>'CViewAction',

			),

		);

	}




please help from the Yii dev

If you don’t see a message “GD and FreeType PHP extensions are required” then your GD/FreeType support should be ok.

I would try to generate a completely new yii app and try the captcha on the contact page again.

If it works you have something wrong in your code, if not there is an other problem.

I’ve tried to change the view, models, and controllers related to the contact page with the code of the new applications that I created, but could not as well.

First of all you need to check the requirements - http://www.yiiframework.com/doc/guide/1.1/en/quickstart.installation#requirements

Check the last line "GD extension with FreeType support" should say "passed"

GD extension with freetype support is passed

http://billing.myelektra.com/yiin/requirements/

any solution ?

good you give the link…

check this link on your server - http://billing.myelektra.com/yiin/demos/blog/index.php/site/contact

it’s the contact page of the yii blog demo… here the captcha is shown… at least to me… check if you see the captcha code…

I can see it also in the link.

then I’ve tried to change the view, models and contoller on billing.myelektra.com to that of the examples of these blogs, but the result is the same

the solution …

http://www.yiiframework.com/forum/index.php?/topic/23660-yii-captcha-doesnt-work/

i guess …

or it may be because unwanted echo or white space in config/main.php or other files

Need to write also -


class MyController extends Controller

{

    public function accessRules() {

        return array('allow', 'actions' => array('captcha'), 'users' => array('*'));

    }

}

I haven’t solved this myself, but noticed something that might help.

My CAPTCHA on contact page was working. but on the new captcha I was trying to create I noticed this in the image URL.


/voucher1/index.php/voucher/captcha?v=543cb5a6ebbe2

Using FireBug If I changed it too:


/voucher1/index.php/site/captcha?v=543cb029c6e5c

it would generate the CAPTCHA, so was not an issue with GD or anything.

Not sure if that helps.

UPDATE, the post above solved the problem for me.

You need to specify the action like this -


$this->widget('CCaptcha', array('captchaAction'=>'voucher/captcha'));

I had a captcha image not showing. It was because of this rule of the urlmanager:

‘<lang:\w+>/<module:\w+>/<controller:\w+>/<action:\w+>’=>’<module>/<controller>/<action>’,

which changing to this rule, solved the problem:

‘<lang:\w+>/blog/<controller:\w+>/<action:\w+>’=>‘blog/<controller>/<action>’,