Yii Framework Forum: Ccaptcha Refresh: Invalid Label Js Error - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Ccaptcha Refresh: Invalid Label Js Error Rate Topic: -----

#1 User is offline   boehmi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 16-May 12

Posted 23 November 2012 - 09:34 AM

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?

2) 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

Attached File(s)


0

#2 User is offline   robregonm 

  • Experienced Yii Developer
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 617
  • Joined: 30-July 09
  • Location:Colombia

Posted 23 November 2012 - 09:36 AM

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

Regards.
Ricardo Obregón
LinkedIn Profile
YiiFramework en Español - http://yiiframework.co/ - Yii Code Generator for Bootstrap
http://obregon.co/ - https://1server.co/
PHP 5.5+, nginx, MySQL, PostgreSQL, Yii 1.x & 2.x, CanJS and more.
Follow me: @robregonm & @obregonco & @1ServerCo.
0

#3 User is offline   boehmi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 16-May 12

Posted 23 November 2012 - 09:38 AM

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
0

#4 User is offline   robregonm 

  • Experienced Yii Developer
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 617
  • Joined: 30-July 09
  • Location:Colombia

Posted 23 November 2012 - 11:50 AM

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;
});


Ricardo Obregón
LinkedIn Profile
YiiFramework en Español - http://yiiframework.co/ - Yii Code Generator for Bootstrap
http://obregon.co/ - https://1server.co/
PHP 5.5+, nginx, MySQL, PostgreSQL, Yii 1.x & 2.x, CanJS and more.
Follow me: @robregonm & @obregonco & @1ServerCo.
0

#5 User is offline   boehmi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 16-May 12

Posted 26 November 2012 - 04:05 AM

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');
...

0

#6 User is offline   boehmi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 16-May 12

Posted 28 November 2012 - 11:33 AM

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 ;)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users