Yii Framework Forum: Yii captcha doesn't work - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii captcha doesn't work Rate Topic: -----

#1 User is offline   LotusH 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 80
  • Joined: 06-May 11
  • Location:China

Posted 16 September 2011 - 04:19 AM

I found captcha doesn't work with my application without any error and then i checked the blog example's contact page with captcha in the Yii file, also doesn't work.

I then completely rewrote the captchaAction and it doesn't work either.

I'm sure my GD library works fine.

Can anybody help me out? What may be the problem?
0

#2 User is offline   jodev 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 75
  • Joined: 10-January 11
  • Location:The Netherlands

Posted 16 September 2011 - 12:33 PM

View PostLotusH, on 16 September 2011 - 04:19 AM, said:

Can anybody help me out? What may be the problem?


Two things come to mind that you might want to check. First, did you overrie the actions() method in your controller class? You'll need to add the following:

class YourController extends Controller
{
    public function actions()
    {
        return array(
            'captcha' => array(
                'class' => 'CCaptchaAction',
                'backColor' => 0xFFFFFF,
            ),
        );
    }
}


If you did that and it still doesn't work, check your controller access. When you are overwritten accessRules(), you need to make the captcha action available for everyone, like this:

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


Hope that helps.
3

#3 User is offline   LotusH 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 80
  • Joined: 06-May 11
  • Location:China

Posted 17 September 2011 - 03:25 AM

View Postjodev, on 16 September 2011 - 12:33 PM, said:

Two things come to mind that you might want to check. First, did you overrie the actions() method in your controller class? You'll need to add the following:

class YourController extends Controller
{
    public function actions()
    {
        return array(
            'captcha' => array(
                'class' => 'CCaptchaAction',
                'backColor' => 0xFFFFFF,
            ),
        );
    }
}


If you did that and it still doesn't work, check your controller access. When you are overwritten accessRules(), you need to make the captcha action available for everyone, like this:

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


Hope that helps.


Thanks for your remind jodev :) . I think I forgot to add access rules. But I solved this in a much more complicated way. I want to customize my captcha and I found captcha,both mine and Yii's, cannot be rendered inside the framework anyway (Maybe because of the access rules you remind me). So I have to put it outside the framework in the root file, problem is, in this way, it cannot share sessions with Yii, so i can't pass the captcha result to validate. I use cache to solve it. Well... whatever, I've solved it though in an inefficient way. And i don't want to entangle on this issue anymore. I've wasted 3 days on this. Really tired about it ;).

Thank you again. I'll try your solution if i want to use Yii's captcha someday.
0

#4 User is offline   paviktherin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 18-July 12

Posted 10 April 2013 - 06:13 PM

View Postjodev, on 16 September 2011 - 12:33 PM, said:

Two things come to mind that you might want to check. First, did you overrie the actions() method in your controller class? You'll need to add the following:

class YourController extends Controller
{
    public function actions()
    {
        return array(
            'captcha' => array(
                'class' => 'CCaptchaAction',
                'backColor' => 0xFFFFFF,
            ),
        );
    }
}


If you did that and it still doesn't work, check your controller access. When you are overwritten accessRules(), you need to make the captcha action available for everyone, like this:

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


Hope that helps.



Thank you!!! This worked for me. I just needed to add the captcha into the allowed actions.
1

Share this topic:


Page 1 of 1
  • 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