Yii Framework Forum: Captcha In Yii Framework Don't Appear (Show) - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Captcha In Yii Framework Don't Appear (Show) Rate Topic: -----

#21 User is offline   xander 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 10-September 12

Posted 14 September 2015 - 07:29 PM

The Complete Solution.


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,
			),
        	);
	}

	public function accessRules()
	{
		return array(
			array('allow', 'actions'=>array('captcha'),
                		'users'=>array('*'),
            		),
		);
	}



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">
		<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; ?>

0

#22 User is offline   DollarsignA.H.64 :) 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 16-September 13

Posted 15 September 2015 - 05:11 AM

Sometimes (actually many times) this bug is because of a unicode BOM at the top of a file within our runtime.

If the bug is about BOM :

The most important note we must be aware about it is the headers_sent() which will return false even if you have a BOM has been sent in text/html content type (which false means no header has been sent yet which is not the real answer). This happened for me via PHP 5.5.6 on windows 7 (xampp)

Thus how you can find whether the BOM has been sent or not... I used exit(); within my code either in my module class (extending CWebModule) especially in my beforeControllerAction and I used my firebug to find is there any byte in the server response or not.

The result must be 0B but if there is a BOM you will have 3B and the code in your response.
My problem was about my language files have been edited one time in a notepad window (netbeans will not add BOM but notepad will add).

EDITED :
You may have no bytes (no BOM) in the first of actions method of your controller (because it is only the declaration). I had tracked the bug even to the CCaptchaAction Class to the header('Content-Type: image/png'). And there I realized headers_sent() says there is not header has been sent.

This post has been edited by Ali Hashemian (alix): 15 September 2015 - 05:17 AM

0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users