Forums

reCAPTCHA and ServerSide validation

tcrow 03 Aug, 2010
Hello World!

Firstly, I must say this component is simply fantastic! Kudos to the people working on it.

That being said I wanted to check if this issue I'm having is a bug or not. So here goes...

I setup reCAPTCHA to work with a form that I created. I then decided to add some ServerSide Validation to check if any of the input already existed in my db.

What I noticed was that when the ServerSide Validation was active the reCAPTCHA would not display an error and the form was submitted (and the serverside validation did it's thing..). However, if the ServerSide Validation was turned off, the reCAPTCHA would throw an error if an incorrect response was entered.

Could this be an issue? I tried debugging the chronoforms code myself but I couldn't find the cause of the issue.

Any helpful suggestions?

Cheers,
-Turner

EDIT: After further looking into the issue I noticed that this error only occurs when a duplicate entry is sent using the form. For example: In my registration form I allow input for email. However, in my serverside validation I make sure there is no other person registered with the same email. If there is...then I return an error message. So back to the problem..if I try using the form and enter [email]admin@something.com[/email] in the email field and enter garbage in the reCAPTCHA, the form will proceed if [email]admin@something.com[/email] is already registered. Granted the server side validation will throw an error. But the form should not have been submitted in the first place.
GreyHead 05 Aug, 2010
Hi tcrow,

I suspect that this is a consequence of the way the sequence of events runs after the form is submitted. Serverside validation is run first - before the plugin code that checks the ReCaptcha.

I think this explains the pattern you are seeing.

I don't think that there is an easy fix for it except to recode Chronoforms with a new plugin trigger to run before the serverside validation :-(

Bob
tcrow 10 Aug, 2010
Hi Bob,

Many thanks for the useful insight!! What you say does make a lot of sense. Let me see if I can figure it out. I'll be sure to post my findings.

Oh btw, while using reCAPTCHA I decided that I wanted to make use of custom recaptcha themes, so I had to hack the recaptcha plugin a bit. Here is the code...


FILE NAME: cf_recaptcha.php
LOCATION: com_chronocontact/plugins

FUNCTION: onload( $option, $row, $params, $html_string )

Original Code Snippet 
----------------------
       $script = "
        
		var RecaptchaOptions = {
			theme : '".$params->get('theme')."',
			lang  : '".$params->get('lang')."' 
		};
    		";

Modified Code Snippet
----------------------
    	if ($params->get('theme') == "custom" ){
         $script = "
				var RecaptchaOptions = {
					theme : '".$params->get('theme')."',
					custom_theme_widget : 'recaptcha_widget',
					lang  : '".$params->get('lang')."' 
				};
    		";
		} else {
        $script = "
        
		var RecaptchaOptions = {
			theme : '".$params->get('theme')."',
			lang  : '".$params->get('lang')."' 
		};
    		";
    	}


So now if the user selects 'custom' in the theme setting of the recaptcha plugin, it will make use of the div that the user has specified in the form code. For more on customization see here -> http://code.google.com/apis/recaptcha/docs/customization.html

Thanks again!

Cheers,
-Turner
GreyHead 11 Aug, 2010
Hi Turner,

I'm not sure I understand the problem. Can you post the serverside validation script that you ae using.

The problem may be because the server-side validation is itself a function and defining a function from within a function is causing some problems. It's usually OK to use a $db call inside the serverside script.

Bob
nml375 11 Aug, 2010
Hi Turner & Bob,
If I (re)read the original post correctly, you are actually looking for something behaving like the LiveValidation javascript validation - running "clientside"? In order to achieve that, you'll need some custom ajax-request code.

In essence, what you describe is the expected behaviour; a set of tests are run serverside once the data has reached the server (been submitted). These include the serverside validation and the recaptcha check. Once the data has passed all tests, the post-submission processing (email, DB Storage, on submit before/after email, other plugins) is done, or the first error in the validation is posted.

/Fredrik
This topic is locked and no more replies can be posted.