Monday, March 30, 2009

Why is validation called twice?

Ive noticed this numerous times when creating my own methods for model
validation. When I do a debug() within the method, it outputs the data
twice, which means the validation is happening twice. Now this hasnt
been a problem until now. Im trying to get recaptcha working correctly
using model validation, heres my code:

/**
* Validate recaptcha
* @param array $data
* @return boolean
*/
function recaptcha($data) {
App::import('Vendor', 'recaptcha', array('file' => 'recaptcha.php'));
$private = Configure::read('Settings.captcha_private');
$public = Configure::read('Settings.captcha_public');

$verify = recaptcha_check_answer($private, env('REMOTE_ADDR'), $this-
>data[$this->name]['recaptcha_challenge'], $this->data[$this->name]
['recaptcha']);

debug($verify);

return ($verify->is_valid) ? true : false;
}


And the model validation:

'recaptcha' => array(
'recaptcha' => array(
'rule' => array('recaptcha'),
'message' => 'captchaFailed'
)
)

The problem is that recaptcha is valid the first time, but since it
validates twice, it fails the second time, thus causing my form never
to validate. As you can see in the debug below, its called twice.

app/app_model.php (line 157)

ReCaptchaResponse Object
(
[is_valid] => 1
[error] =>
)


app/app_model.php (line 157)

ReCaptchaResponse Object
(
[is_valid] =>
[error] => incorrect-captcha-sol
)

How am I to fix this problem?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: