Gossamer Forum
Home : Products : Links 2.0 : Customization :

Captcha for Rating?

Quote Reply
Captcha for Rating?
Hi,

is it possible to use the catcha solution from

http://www.gossamer-threads.com/...d;page=unread#unread

also for the rating?

Best,
Karl
Quote Reply
Re: [Karl] Captcha for Rating? In reply to
Certainly! Referring to the post you linked, do the following:

1. Same. If you already have captcha on your add form, skip this step.

2. Edit rate.cgi, sub main as shown:

Code:
sub main {
# --------------------------------------------------------
local (%in) = &parse_form;

if ($in{'rate'}) {
# >>> Captcha Mod next line
($in{'captcha'} ne '') ? &captcha : &site_html_rate_failure("You did not enter the security code.") and return; # <<<

}
elsif ($in{$db_key} =~ /^\d+$/) {
my (%rec) = &get_record ($in{$db_key});
($rec{$db_key} eq $in{$db_key}) ?
&site_html_rate_form (%rec) :
&site_html_rate_failure ("Unkown Link ID: $in{$db_key}");
}
else {
print "Location: $build_ratings_url/\n\n";
}
}


3. Add this new sub to add.cgi, above sub rate_it:


Code:
sub captcha {
#------------------------------------------
require "admin/captcha/captcha.pl";
$code = ($in{'code'});
$crypt = ($in{'crypt'});
if ($code && $crypt){

# check code
$result = &checkCode($code,$crypt);

if ($result == 1){
&rate_it;
}
elsif ($result == -1){
&site_html_rate_failure("<b>Failed!</b> Reason: code expired. Possible cause: code was issued too long ago. Try the new code below.") and return;
}
elsif ($result == -2){
&site_html_rate_failure("<b>Failed!</b> Reason: invalid code (not in database). Possible causes: code already used or expired. Try the new code below.") and return;
}
elsif ($result == -3){
&site_html_rate_failure("<b>Failed!</b> Reason: invalid code (code does not match crypt). Possible cause: characters not entered correctly. Try the new code below.") and return;
# note - once a solution is tried it is expired, even if it failed
}
else {
&site_html_rate_failure("You did not enter the security code.") and return;
}
}

} # end sub


4. Edit the rate routines as shown for the add routines.

5. Add this routine if you do not already have it for the add form. This one routine will run the Captcha for both add and rate (and any others).

6. Make these edits in the rate templates.

That should do it for ya!


Leonard
aka PerlFlunkie

Last edited by:

PerlFlunkie: Mar 15, 2008, 10:25 AM
Quote Reply
Re: [PerlFlunkie] Captcha for Rating? In reply to
Hello PerlFlunkie,

many thanks for your fast help!

must i add also the same lines in site_html_templates.pl as for add.cgi?

Best,
Karl
Quote Reply
Re: [Karl] Captcha for Rating? In reply to
Yes. Let me know if there's any problems...Wink


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Captcha for Rating? In reply to
Hi PerlFlunkie,

it works perfectly!

There was a small typing error in your code

if ($in{'rate'}) {
# >>> Captcha Mod next line
($in{'captcha'} ne '') ? &captcha : &site_html_rate_failure("You did not enter the security code.") and return; # <<<

}

it must read:

if ($in{'rate'}) {
# >>> Captcha Mod next line
($in{'code'} ne '') ? &captcha : &site_html_rate_failure("You did not enter the security code.") and return; # <<<

}

All the best,
Karl