diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-06-01 23:58:49 -0700 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-06-01 23:58:49 -0700 |
commit | f0395984109bb279b6dac157bff885b45e489a52 (patch) | |
tree | 091d55c9325ce7562728049deeaf411a204ed12f /modules | |
parent | 02a840c84cada5a1c0cc0768f350424460310e5d (diff) |
Move recaptcha widget into a view for clarity. Also, wrap it in a
setTimeout() call so that on subsequent reloads (which happen when you
fail to validate the form) it has time to rebuild the DOM before
calling the JS which tries to inject the Recaptcha HTML.
Fixes ticket #327
Diffstat (limited to 'modules')
-rw-r--r-- | modules/recaptcha/libraries/Form_Recaptcha.php | 17 | ||||
-rw-r--r-- | modules/recaptcha/views/form_recaptcha.html.php | 11 |
2 files changed, 14 insertions, 14 deletions
diff --git a/modules/recaptcha/libraries/Form_Recaptcha.php b/modules/recaptcha/libraries/Form_Recaptcha.php index d804fd78..4c0c4997 100644 --- a/modules/recaptcha/libraries/Form_Recaptcha.php +++ b/modules/recaptcha/libraries/Form_Recaptcha.php @@ -39,20 +39,9 @@ class Form_Recaptcha_Core extends Form_Input { "http://recaptcha.net/api/getkey</a>"); } - $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 = "<div id=\"gRecaptcha\" />"; - $html .= "<script type=\"text/javascript\" "; - $html .= "src=\"http://api.recaptcha.net/js/recaptcha_ajax.js\"></script>"; - $html .= "<script type=\"text/javascript\">"; - $html .= "Recaptcha.create(\"$public_key\", \"gRecaptcha\", {" . $options . "});"; - $html .= "</script>"; - return $html; + $view = new View("form_recaptcha.html"); + $view->public_key = $public_key; + return $view; } /** diff --git a/modules/recaptcha/views/form_recaptcha.html.php b/modules/recaptcha/views/form_recaptcha.html.php new file mode 100644 index 00000000..f5b36335 --- /dev/null +++ b/modules/recaptcha/views/form_recaptcha.html.php @@ -0,0 +1,11 @@ +<div id="gRecaptcha"></div> +<script type="text/javascript" src="http://api.recaptcha.net/js/recaptcha_ajax.js"></script> +<script type="text/javascript"> + setTimeout(function() { + Recaptcha.create( + "<?= $public_key ?>", + "gRecaptcha", + { theme: "white", callback: Recaptcha.focus_response_field }); + }, 0); +</script> + |