View Single Post
  #21 (permalink)  
Old 07-17-2008, 05:16 PM
momo momo is offline
New Pligger
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Red face Another version of Recaptcha when Submitting News Stories

Thanks ruptan for all the work that was done on this. After reviewing your post and the attached files, I noticed an error in the post that was not in the attached files. I also modified the behavior so that when a user enters an invalid Captcha, the user will return to the same page with the error message from recaptcha.

First, I am using Pligg 9.9.0

Step 1: Open submit_step_2.tpl:

Find :
PHP Code:
<input type="submit" value="{#PLIGG_Visual_Submit2_Continue#}" class="submit" /> 
BEFORE THIS PLACE:
PHP Code:
            <?php 
                
require_once(captcha_captchas_path '/reCaptcha/libs/recaptchalib.php');
                
$publickey get_misc_data('reCaptcha_pubkey'); // you got this from the signup page
                
echo recaptcha_get_html($publickey);
            
?>
(this code was found in modules->captcha->captchas->recaptcha->captcha.tpl)
Step 2: Open Submit.php (this is where the typo is on ruptan's post).

Find:

PHP Code:
// submit step 2

function do_submit2() {
    global 
$db$main_smarty$dblang$the_template$linkres$current_user
AFTER THIS PASTE:
PHP Code:
//captcha
if(enable_captcha == 'true') {
            
        require_once(
'recaptchalib.php');        
        
// Get a key from http://recaptcha.net/api/getkey
        
$publickey "YOURPUBLICKEY";
        
$privatekey "YOURPRIVATE";
        
        
# the response from reCAPTCHA
        
$resp null;
        
# the error code from reCAPTCHA, if any
        
$error null;
        
        
# was there a reCAPTCHA response?
        
if ($_POST["recaptcha_response_field"]) {
                
$resp recaptcha_check_answer ($privatekey,
                                                
$_SERVER["REMOTE_ADDR"],
                                                
$_POST["recaptcha_challenge_field"],
                                                
$_POST["recaptcha_response_field"]);
                
                if (
$resp->is_valid) {
                        echo 
"Succesfully verified that you are human.";
                } else {
                        
# set the error code so that we can display it
                        
$error $resp->error;

                }
        }    
            
        if (!
$resp->is_valid) { // if incorrect captcha code was entered
              
echo $error;
            
do_submit1();
            return;
        }
        
// fin capthca 
Step 3:

In Submit.php,

FIND:

PHP Code:
}

// submit step 3 
REPLACE WITH:
PHP Code:
} }

// submit step 3 
In Summary: The code listed on the site for submit.php incorrectly places new captcha code in such a way that the function do_submit2() never gets created. However, the code listed in the attachment is correct. If you don't look at that code, you will not get this to work. I also changed the behavior so that if it is a human who typed wrong, they can refill the submit page.

Thanks again for even figuring this stuff out, I hope that this post clarifies some of the issues you may encounter getting this to work.

Kudos also goes to ednet, who had a similar post. His showed me the typo I pointed out...

http://forums.pligg.com/pligg-mods/8...recaptcha.html

If you'd like to see an example: www.TotalExperience.com