From af56018f7c7335a3a98c1871a56991c08745dacb Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 26 Jan 2009 16:16:00 +0000 Subject: Forgot to add the Form_Recaptcha class --- modules/recaptcha/libraries/Form_Recaptcha.php | 75 ++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 modules/recaptcha/libraries/Form_Recaptcha.php (limited to 'modules/recaptcha') diff --git a/modules/recaptcha/libraries/Form_Recaptcha.php b/modules/recaptcha/libraries/Form_Recaptcha.php new file mode 100644 index 00000000..f834f068 --- /dev/null +++ b/modules/recaptcha/libraries/Form_Recaptcha.php @@ -0,0 +1,75 @@ + '', + 'value' => '', + ); + + public function __construct($name) { + parent::__construct($name); + $this->error_messages("incorrect-captcha-sol", t("The values supplied to recaptcha are incorrect.")); + $this->error_messages("invalid-site-private-key", t("The site private key is incorrect.")); + } + + public function render() { + $public_key = module::get_var("recaptcha", "public_key"); + if (empty($public_key)) { + throw new Exception("@todo NEED KEY " . + "http://recaptcha.net/api/getkey"); + } + + $server = "http://api.recaptcha.net"; + + $options[] = "callback: Recaptcha.focus_response_field"; + $options[] = "lang: \"" . Kohana::config("locale.root_locale") . "\""; + $options[] = "theme: \"white\""; + $options = implode(", ", $options); + + $html = "
"; + $html .= ""; + $html .= ""; + return $html; + } + + /** + * Validate this input based on the set rules. + * + * @return bool + */ + public function validate() { + $input = Input::instance(); + $challenge = $input->post("recaptcha_challenge_field", "", true); + $response = $input->post("recaptcha_response_field", "", true); + if (!empty($challenge)) { + $this->_error = recaptcha::is_recaptcha_valid($challenge, $response); + if (!empty($this->_error)) { + $this->add_error($this->_error, 1); + } + } + $this->is_valid = empty($this->_error); + return empty($this->_error); + } + +} \ No newline at end of file -- cgit v1.2.3