reCaptcha for submit – Pligg v9.9.5

One of the most sought after modules for Pligg is adding reCaptcha for story submissions.

Pligg member fhelik came up with the solution by adding reCaptcha on step 2, this however isn’t the ideal place for it to be, the reason being, most of your spam is being submitted by a bot.  Once the bot registers an account, it then attempts to submit a submission, once it hits step 2, it will be blocked because of the reCaptcha, but what you are left with is an incomplete story submission that will show up in your “Upcoming” section.

Using fhelik, I simply modified it and added it to step 1, this way if it’s a bot doing the story submission, it won’t make it past submitting a URL, and it will prevent incomplete submissions from littering my “Upcoming” pages.

Backup each file before installing this module

I have this installed on Pligg v9.9.5, a demo can be seen at FAQ PAL.

Step 1: open submit_step_1.tpl

Find:

{if $Submit_Require_A_URL neq 1}{#PLIGG_Visual_Submit_Editorial#}{/if}

before, add:

{php}
require_once(‘recaptchalib.php’);
$publickey = "PUBLICKEY"; // you got this from the signup page
echo recaptcha_get_html($publickey);
{/php}

Step 2: open submit.php

Find:

// submit step 1
function do_submit1() {
global $main_smarty, $db, $dblang, $current_user, $the_template;

after, add:

//captcha
if(enable_captcha == ‘true’) {

        require_once(‘recaptchalib.php’);
        // Get a key from http://recaptcha.net/api/getkey
        $publickey = "ENTER YOURPUBLICKEY";
        $privatekey = "ENTER 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
            $main_smarty->assign(‘register_error_text’, "badcode");
            $main_smarty->display($the_template . ‘/submit_errors.tpl’);
            return;
        }
        // fin capthca

Find:

}

// submit step 2
function do_submit2() {

Replace, with:

}}

// submit step 2
function do_submit2() {

Download the latest reCaptcha library from here and upload to your “root”. 

You will also need reCaptcha keys for your site, you will need to register and add your site to reCaptcha.  Register here.

In the above snippets, retype all instances of the single apostraphe ( ‘ ) as they are not appearing properly here. In the download they will appear properly however.

If the user/bot fails to enter the correct reCaptcha code, they will be forwarded to your error page controlled by submit_errors.tpl, I have not come with a custom error message for this, maybe someone can submit one.

This should eliminate almost all spam submissions.

  ReCaptcha for Submit (8.0 KiB, 328 hits)

Error page:

If the user enters the wrong reCaptcha code, heres a sample error page complete with error message and back button.

Download the file below and upload it to templates/yget .

  Captcha Error (370 bytes, 212 hits)

Go to submit.php and change:

       if (!$resp->is_valid) { // if incorrect captcha code was entered
            $main_smarty->assign(’register_error_text’, "badcode");
            $main_smarty->display($the_template . ‘/submit_errors.tpl’);
            return;
        }
        // fin capthca

to,

       if (!$resp->is_valid) { // if incorrect captcha code was entered
                $main_smarty->assign(’submit_error’, ‘badcode’);
                $main_smarty->assign(‘tpl_center’, $the_template . ‘/captcha’);
                $main_smarty->display($the_template . ‘/pligg.tpl’);
                return;
        }
        // fin capthca

Again, you can test this on FAQPAL

If you enjoyed this post, make sure you subscribe to my RSS feed!

  • First issue has been solved. now I have another issue, I got blank page after click ubmit button. ;)

  • First issue has been solved. now I have another issue, I got blank page after click umit buton.
    Please help in solving this error
  • First issue has been solved. now I have another issue, I got blank page after click ubmit buton.
    Please help in solving this error
  • First issue has been solved. now I have another issue, I got blank page after click ubmit button.
    Please help in solving this error
  • I created a custom error page which has been posted above for download and instructions on how to implement it.
  • @Sandi, receiving a 500 error when trying to load your site.

    Can you email me your submit.php and submit_step1.tpl files so I can have a look?

    utopianwd [@] msn.com
  • @Geoserv , I am entered a correct or incorrect reCaptcha code always receive a blank screen,
    I use your custom error and implement it follow your instructions.

    my site www.freebiesup.com
  • @Sandi, if you entered an incorrect reCaptcha code, you will by default receive a blank screen, that is why I created a custom error page which has been posted above for download and instructions on how to implement it.
  • Yes I have the template file submit_errors.tpl
  • @Sandi, I haven't tested this in RC4, only 9.9.5, but it should work.

    Do you have the template file submit_errors.tpl ?
blog comments powered by Disqus