Prblem with Captcha

I’ve got a form with a captcha code, and every time I try to submit the form with the correct captcha code, the validator says, that the code is wrong. This happens in 2 of 4 forms. The 2 forms (which doesn’t accept the right code are part of modules), the other 2 form (which work fine) are not in modules.

Any suggestions what’s wrong, or how to debug this issue?


I had the exact same problem with reCaptcha. It was working fine until I wanted to save the form (CActiveRecord). I tried to use it for my registration process and saving a user in the DB :confused:

I ended up writing a dummy "human-verifier" with math questions (ie: 5+6=? 1-2=? etc)

But Captcha would be much nicer!


hi imehesz,

i still couldn’t figure out what’s going wrong there, but i think this must be a problem of the current release, becuase in two other projects of mine (where i haven’t updated the framework) it works very well.

i hope the developers of yii could help solving this problem!

oh really?

I haven’t tried that in other/older versions. Maybe I should. I didn’t have time to dig into the deep end of the Yii core, so I’m not sure what’s causing it :confused:

Thanks for the tip!


You cannot use captcha through different controllers. If you retrieve the captcha from AController you must validate against AController because the session entry of the captca is controller based.


Here is what’s happening right now (note: I’m using the reCaptcha ext)

  • I have a registration form, with 3 fields. Username and Password + the captcha

  • Here are my test cases:

I’ve been trying to solve this for weeks. Driving me nutZ …

Any ideas?



ps: obviously, I’m using the same controller here, no trickery there

I’m not trying to use captcha through different controllers. The problem only occures when I use captcha in a form which belongs to a module. Using captcha with forms which doesn’t belong to a module works fine.

hello again,


Here is an idea, what if you just create a scenario specifically for the registration? I think in that case, it wouldn’t try to verify the captcha again. I’ll try that and let you know what happened.



Okay, here is how it works for me now with the reCaptcha plugin.


public function actionRegister()


  $form = new User();

  $form->scenario = 'registerwcaptcha';




    // and here is the actual HACKY part

    $form->scenario = NULL;

    // save user registration




User Model:

public function rules()


  return array(





                     'privateKey'=> ENVII_CAPTCHA_PRIVATE_KEY, 'on' => 'registerwcaptcha'





And it works like a charm, [color="#FF0000"]FAILS[/color] and [color="#006400"]PASSES[/color] when it has to :)


Thanks a lot!, I should add your notes to the documentation page.