I have two forms (login and register) on single page and they both required captcha. I know is not common but I cannot change this biz requirement because this is a special request. Currently they both shared the same captcha but I cannot refresh them independently. Anyone has any ideas?
Someone suggests that I would design the page so that only one displays and is used for both login and register functions. This is maybe an option but I want to make sure I can be done with two captchas.
i and softark seems give the solution same ! when i commit my post just see the softark has posted !
the key code is this :
* Returns the session variable name used to store verification code.
* @return string the session variable name
protected function getSessionKey()
return self::SESSION_VAR_PREFIX . Yii::app()->getId() . '.' . $this->getController()->getUniqueId() . '.' . $this->getId();
the validation use this key to check in the $session . “$this->getId()” is the captchaActionId , you just make it different !
I also have tried some, but in vain. I’m very sorry.
OK, I think I got it.
Try this …
public function rules()
array('verifyCode1', 'captcha', ...
array('verifyCode2', 'verifycaptcha2', ...
public function verifycaptcha2($attribute, $params)
$captcha2 = Yii::app()->getController()->createAction('captcha2nd');
if (!$captcha2->validate($this->verifyCode2, false))
$this->addError('verifyCode2', 'invalid captcha.');
The validation for the 2nd captcha is performed by a dedicated function called ‘verifycaptcha2’ in which the proper instance of the 2nd captcha action is created by ‘Yii::app()->getController()->createAction(‘captcha2nd’)’.