2012-05-14 37 views
1

我想解除幾個窗體上的recapthca驗證,但一直沒有任何運氣。我總是從我的「recaptcha_response_field」中得到一個錯誤,指出「您沒有正確輸入字詞,請重試。」cakephp recapthca插件未設置

我需要recaptcha在我的大多數形式,但我想跳過幾個。我嘗試過「MultivalidatableBehavior」http://bakery.cakephp.org/articles/dardosordi/2008/07/29/multivalidatablebehavior-using-many-validation-rulesets-per-model,但我無法讓它工作。

任何想法,我可能如何能夠得到這個工作?

https://github.com/tbsmcd/recaptcha_plugin

感謝, 巴特

回答

2

你將不得不修改插件行爲做...這將是做到這一點的最簡單的方法,你也能做到這一點的行爲,但這種方式簡單易行。

//Your Controller 
function add(){ 
$this->{$this->modelClass}->reCaptcha = true; 
if(!empty($this->data)){ 
$this->{$this->modelClass}->save($this->data); 
} 
} 

//Edit Recaptcha ValidateBehavior 
function beforeValidate(&$model) { 
if(isset($model->reCaptcha) && $model->reCaptcha){ 
$model->validate['recaptcha_response_field'] = array(
'checkRecaptcha' => array(
'rule' => array('checkRecaptcha', 'recaptcha_challenge_field'), 
'required' => true, 
'message' => 'You did not enter the words correctly. Please try again.', 
), 
); 
} 
}