Captcha In Yii Framework Don't Appear (Show)


(Walcoott) #1

what’s wrong? Please help…

------Model--------

public $verifyCode;

public function rules()

{

return array(array(‘verifyCode’, ‘captcha’, ‘allowEmpty’=>!CCaptcha::checkRequirements()),

);

}

public function attributeLabels()

{

return array(‘verifyCode’=>‘Verification Code’, );

}

--------Controller

public function actions(){

return array(

// captcha action renders the CAPTCHA image displayed on the user registration page

‘captcha’=>array(

‘class’=>‘CCaptchaAction’,

‘backColor’=>0xFFFFFF,

),

);

}

public function accessRules()

{

return array(

array(‘allow’, ‘actions’=>array(‘create’,‘update’,‘captcha’),

‘users’=>array(’@’),),

);

}

-------------------View--------------

<?php $form=$this->beginWidget(‘CActiveForm’, array(

‘id’=>‘project-form’,

‘enableAjaxValidation’=>false,

));

?>

<?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.

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

<?php echo $form->error($model,‘verifyCode’); ?>

</div>

&lt;?php endif; ?&gt;

<div class="row buttons">

<?php echo CHtml::submitButton($model->isNewRecord ? ‘Create’ : ‘Save’); ?>

</div>

<?php $this->endWidget(); ?>


(Alirz23) #2

what error you get? can you paste you stacktrace


(Czaty) #3

This form is displaying only for authenticated users?

In rules you have:




return array(

array('allow', 'actions'=>array('create','update','captcha'),

'users'=>array('@'),),

);




(Walcoott) #4

[color="#006400"]/* MOD: unnecessary quote removed */[/color]


(Aneesh) #5

Check your controller action rules with this




public function accessRules() 

{

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

}



try to change the ‘@’ (‘users’ => array(’’)) with '’.

Thanks


(Walcoott) #6

doesn’t work


(Walcoott) #7

http://freakshare.com/files/d3u484h2/999.rar.html

index.php?r=site/login -> work

index.php?r=users/create -> dont work


(Aneesh) #8

Appear the same UI again…?

Is it work in your Yii application contact form…?


(Walcoott) #9

captcha for contact form works, but I want captcha in other place


(Aneesh) #10

Add the following in the controller




        public function actions()

	{

		return array(

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

			'captcha'=>array(

				'class'=>'CCaptchaAction',

				'backColor'=>0xFFFFFF,

			),

			

		);

	}



In model

a. Define the variable




public $verifyCode;



b. Add variable in access rules




        public function rules()

	{

		return array(

			

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

		);

	}



In the view file




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

	<div class="row"><tr>

                

                

		<div>

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

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

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

                    <?php echo $form->error($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; ?>



Thanks


(Walcoott) #11

doesn’t work…


(Garyw3058) #12

Hi there,

I am experiencing a similar problem, with the captcha image not displaying on the host server, and yet on my localhost the captcha image is visible. I have tried the forums to get some help but I am stuck. I’ve tried changing all the files as displayed on this and other posts, but to no avail.

I am also experiencing issues when I click on ‘Get a new code’ on both localhost and on the server. The below output is shown on a blank white screen:

{"hash1":651,"hash2":651,"url":"\/index.php\/site\/captcha?v=513d69a205490"}

I don’t know if this problem is related to the previous issue? All I know is that I have probably need to do some more reading about ‘routing’.

If anyone can point me in the right direction it will be much appreciated. Thank you.

Yii 1.1.13


(Faridplusplus) #13

make sure that GD (GD2) extension is enabled in the php.ini config file.


(Garyw3058) #14

Hi faridplus,

thanks for your help.

The server is configured for captcha according to the Yii’s functional testsite file (see attached image).

3939

Screen shot 2013-03-09 at 2.36.39 PM.png

So I am assuming that the host server php.ini file enables GD functionality. I’m in the process of upgrading to a new host environment in the next few days, so I will see if that helps.

I haven’t quite worked out why on clicking the link “Get new code” generates this output though:

3942

Screen shot 2013-03-15 at 12.45.56 PM.png

Cheers


(Faridplusplus) #15

Hi, this time use Firebug and look at Net panel when you click on the ‘Get a new code’. it should display 2 separate requests: one for getting that JSON object ({“hash” : … , “url” : …}) and another for loading the actual image. If any error happens, Firebug usually reports it.


(Garyw3058) #16

Thanks faridplus for you time.

I get no error when I click on ‘Get new code’ when I view the result on Firebug and the Net panel.

3957

Screen shot 2013-03-16 at 3.01.29 PM.png

However, when I go to the index page of the web site I get this result:

3959

Screen shot 2013-03-16 at 3.00.49 PM.png

Something is amiss with either my setup on the host server or my config files.


Update:

To fix the issue regarding the missing ‘captcha’ image, I contacted my host provider to comment out the line in the php.ini file -

;error_reporting = E_ALL & ~E_DEPRECATED

and to turn ‘safe_mode’ to ‘off’.

cheers

Gaz


(Carvan2010) #17

Dear all…

I wanted to add captchaExtended-1.0.2 because captcha was not working,

I install that and follow instructions but didn’t work.

kindly guide me . I am usning (yii-1.1.14.f0fee9)


(Thkhen) #18

I am using yii 1.1.14 but still can’t get the captcha image display. I had enable GD2 extension, change the sate_mode to off still didn’t make any changes. Please help.


(Aneesh) #19

In your controller access rules add the following




            array('allow',                 

                'actions'=>array('captcha'),

                'users'=>array('*'),

            ),


(Thkhen) #20

thanks a lot, it really work.