Ccaptcha Refresh: Invalid Label Js Error

Hey folks,

i want to use CCaptcha for my contact form, everything (rendering, validation, error-Messages etc.) works fine but the refresh-functionality

  1. My first approach was to use set "showRefreshButton" to true, but when i load the page i got an JS Error

"ReferenceError: dummy is not defined


dummy"



This "dummy"-Code is registered in the function registerClientScript() of CCaptcha… wtf?

  1. Then i tried to use the "clickableImage" method

If i click the image an Ajax Request is sent… the answer also looks pretty good, but i get a jQuery Error "Invalid Label" (see Screenshot)

I have other projects where everything works well (the Ajax answer looks similar)

Yii Version is 1.1.7

Does anyone have an idea what i could do wrong?

Thanks in advance

Please try taking a look at SiteController… it will give some tips about how to implement captchas.

Regards.

I implemented it exactly like in the default Yii-application (i’m not using CCaptcha for the first time and never had problems like that)

As i said, everything besides the refresh works fine

Interesting… Could you please check that the generated JS script for captcha, is ok?

Mine looks like this:





jQuery('#yw0').after("<a id=\"yw0_button\" href=\"\/index.php\/site\/captcha?refresh=1\">Get a new code<\/a>");

jQuery(document).on('click', '#yw0_button', function(){

	jQuery.ajax({

		url: "\/index.php\/myController\/captcha?refresh=1",

		dataType: 'json',

		cache: false,

		success: function(data) {

			jQuery('#yw0').attr('src', data['url']);

			jQuery('body').data('captcha.hash', [data['hash1'], data['hash2']]);

		}

	});

	return false;

});



Hi,

mine looks like this:


jQuery(function($) {jQuery('#yw0').live('click',function(){

jQuery.ajax({

url: "\/contact\/default\/captcha\/refresh\/1\/",

dataType: 'json',

cache: false,

success: function(data) {

jQuery('#yw0').attr('src', data['url']);

jQuery('body').data('captcha.hash', [data['hash1'], data['hash2']]);

}

});

By debugging i discovered that jQuery is trying to eval the received JSON data instead of decoding it… ? Then it crashs with the “invalid label” error, because it’s no JS code ^^

I can’t use the refresh button, because of the “dummy” Code generated by CCaptchas registerClientScript():


...

		if($this->showRefreshButton)

		{

			$cs->registerScript('Yii.CCaptcha#'.$id,'dummy');

...

I fixed it by changing the JavaScript in CCaptchas registerClientScript() to


jQuery(function($) {jQuery('#yw0').live('click',function(){

jQuery.ajax({

url: "\/contact\/default\/captcha\/refresh\/1\/",

dataType: 'text', // <--

cache: false,

success: function(data) {

data = jQuery.parseJSON(data); // <--

jQuery('#yw0').attr('src', data['url']);

jQuery('body').data('captcha.hash', [data['hash1'], data['hash2']]);

}

});

and commenting out the $cs->registerScript(‘Yii.CCaptcha#’.$id,‘dummy’); line

But i feel bad by changing the frameworks code ;)