From 13c82d976c4ac5f03ab4f76f6886b78802e35d81 Mon Sep 17 00:00:00 2001 From: ctrlaltca <> Date: Mon, 7 Jan 2013 15:45:07 +0000 Subject: reworked fix for #431 --- framework/Web/UI/WebControls/TReCaptcha.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'framework/Web/UI/WebControls') diff --git a/framework/Web/UI/WebControls/TReCaptcha.php b/framework/Web/UI/WebControls/TReCaptcha.php index c6cf4185..31fcf1ca 100644 --- a/framework/Web/UI/WebControls/TReCaptcha.php +++ b/framework/Web/UI/WebControls/TReCaptcha.php @@ -217,7 +217,12 @@ class TReCaptcha extends TWebControl implements IValidatable // if we're in a callback, then schedule re-rendering of the control // if not, don't do anything, because a new challenge will be rendered anyway if ($this->Page->IsCallback) - $this->Page->ClientScript->registerEndScript($this->getClientID().'::refresh','Recaptcha.reload();'); + $this->Page->ClientScript->registerEndScript($this->getClientID().'::refresh', implode(' ', array( + // work-around for "ReCaptchaState is undefined" bug + // (if there's no previous instance yet, regenerating the token is not needed anyway) + 'if (typeof ReCaptchaState != "undefined") '. + ' Recaptcha.reload();', + ))); } public function renderContents($writer) @@ -244,7 +249,7 @@ class TReCaptcha extends TWebControl implements IValidatable ); */ $writer->write($html); - + $cs->registerEndScript('ReCaptcha::EventScript', 'Event.observe(document, "dom:loaded", function() { '.$readyscript.'; } );'); } else @@ -254,11 +259,14 @@ class TReCaptcha extends TWebControl implements IValidatable $cs->registerScriptFile('ReCaptcha::AjaxScript', 'http://www.google.com/recaptcha/api/js/recaptcha_ajax.js'); $cs->registerEndScript('ReCaptcha::CreateScript::'.$id, implode(' ', array( 'if (!$('.TJavaScript::quoteString($this->getResponseFieldName()).'))', + '{', + 'Recaptcha.destroy();', 'Recaptcha.create(', TJavaScript::quoteString($this->getPublicKey()).', ', TJavaScript::quoteString($divid).', ', TJavaScript::encode($options), ');', + '}', ))); } -- cgit v1.2.3