I implemented reCaptcha in my registration form. But i got an error when i instert the right captcha code:
CCaptchaValidator.action “captcha” is invalid. Unable to find such an action in the current controller.
public function actionCreate()
{
$model=new TblUsers;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['TblUsers']))
{
Yii::import('ext.recaptchalib',true);
$privatekey = '6LfgNLoSAAAAAGBVyqeKK9qH_wG5HIGIDd2KotLB';
$resp = recaptcha_check_answer($privatekey, $_SERVER['REMOTE_ADDR'],
Yii::app()->request->getParam('recaptcha_challenge_field'),
Yii::app()->request->getParam('recaptcha_response_field' ) );
$model->attributes=$_POST['TblUsers'];
if($resp->is_valid)
{
if($model->save())
if($this->_identity===null)
{
$this->_identity=new UserIdentity($model->username,$model->password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($this->_identity,$duration);
$this->redirect(array('site/index'));
return true;
}
else
return false;
}
}
else
{
$this->render('create',array(
'model'=>$model,
));
}
}
The above code is my controler where i check the captcha. If its ok, then he should save data in the db and login, with the newly created user. If wrong code, well for now i only get a blank white page. Could need some help here please.
FAST EDIT: Ups i fixed the problem with the right code, i left some junk in the model rule, but its fine now. Even thought i still need some help to handle the thing when the code is wrong, cause i get a blank page now.
just render a different page with error or redirect to a different page without taking any user login actions.
At the moment you are simply returning false if $resp is not correct. You are not rendering anything out in this case. So either render an error page
or redirect to a different page and not take any actions for login or event render the same again with error on the form field for captcha.
As a recommendation take a look at the nesting of your if statements, it is a simple action and you are making it a bit too complex.