We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Recaptcha Plugin Development

Development and Programming

narration's avatar
narration
773 posts
17 years ago
narration's avatar narration

Well, this is really bad. The forum is stripping out <scr-ipt> tags.

It looks like this experiment is the way to have them, as I am seeing from previews. So I will put them back in the code below, and you can remove the dashes.

There is also the early line from the above which should read:

You need the <scr-ipt></scri-pt> bracketing of the added var code from the wiki; it all counts. Also, you should be using <head></head> around all of this for your html.

Maybe you had those script tags actually, and had yours stripped too. But anyway, the code below works, has the passed statement, and discussion above. No first-time funny messages.

Best, & good fortune, Clive

<html>
  <head>

     <scri-pt>
        var RecaptchaOptions = {
           theme : 'clean'
        };
     </scri-pt>

  </head>

  <body>
    <form action="" method="post">
<?php

require_once('/home/edalzell/phplib/recaptcha-php-1.10/recaptchalib.php');
$publickey = "";
$privatekey = "";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# are we submitting the page?
                    # This is where we process the user's response. We don't
                    # do this when the form is initially displayed - only
                    # when the user submits it.
                    if ($_POST["recaptcha_response_field"]) {
                        $response = recaptcha_check_answer(
                            $privatekey, $_SERVER['REMOTE_ADDR'],
                            $_POST['recaptcha_challenge_field'],
                            $_POST['recaptcha_response_field']
                        );

                        if ( $response->is_valid ) {
                            # The user passed the reCAPTCHA test: form submission should continue
                            # Your other form validation logic should go here.
                        
                            # For example
                            # ... validate user input ...
                            # ... store form data in a database ...
                            # ... redirect to 'thank you' page

                            echo "passed";
                        
                        }
                        else {
                            # The user failed the reCAPTCHA test so we need
                            # to fill in the error message and re-try the
                            # form submission
                            $error = $response->error;
                            echo "error: ", $error;
                        }
                    }

               
                    # Display the reCAPTCHA challenge. The first time
                    # through $error will be null.

                    echo recaptcha_get_html( $publickey, $error );
?>
    <br>
    <input type="submit" value="submit" />
    </form>
  </body>
</html>
       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

Your code and mine is the same, except for the <head> tags. I am still seeing that error.

Crazy.

       
narration's avatar
narration
773 posts
17 years ago
narration's avatar narration

Hi - sorry, didn’t spot your reply until today Saturday.

Erin, I see the Notice problem on your site too. I can duplicate it on my own, but not quite exactly, and I think that has to be a clue.

  • if I put in a bad $privatekey value, then I get your Notice on first start with fresh browser, Firefox as normal, or IE6 that I keep around for checking things.

  • But. On your site, the Recaptcha works, and doesn’t give more notices or odd errors. On my site, the Recaptch didn’t work with bad privatekey, and instead always gives me error: incorrect-private-key, or near that wording, for right or wrong typed response.

Not Notice after the first page load, but a consistent error on all others which is printed by our error echo coce, be sure to see.

  • All is fixed on my site when proper $privatekey is replaced in the template.

Bad $publickey in a separate test gives different message, and no Notice, is easy to see, so it’s not that.

Here are two things I can suggest.

  • This is the one I think it is. I would rename the directory where your Recaptcha php library is. Then download and install a new copy of this library from their website. Mine is slightly newer than yours, since I got it after starting to answer you. Maybe they changed something to go with the alteration to template code we noticed earlier.

When you do this, I would leave the directory name the same as they put it for the library, and adjust your code for that. I can’t see what difference this would make but you never know - something in their own idea of security perhaps.

  • the other possibility would be something about your site’s caching. You could just go into Admin:Utilities and clear all site caches. The recaptcha template page should not be cached, and presume that’s how you set it in Template:Preferences.

You may not get this note until you get back, but I know you will enjoy vacation.

Regards, Clive

       
jschutt's avatar
jschutt
452 posts
17 years ago
jschutt's avatar jschutt

Hey Guys,

Anything new with this? I am in a similar boat…

Jesse

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

I got a new job and I no longer have time to work on this, sorry.

       
Komra Moriko's avatar
Komra Moriko
5 posts
17 years ago
Komra Moriko's avatar Komra Moriko

Here is the solution. reCaptcha is looking for a post variable. EE uses {segment_X} to define post variables. So, here is the code that will work. Make sure you set the template to parse PHP on input.

<?php

require_once('recaptchalib.php');

// Get a key from http://recaptcha.net/api/getkey
$publickey = "whatever";
$privatekey = "whatever";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# was there a reCAPTCHA response?
?>
{if segment_4}
<?php
        $resp = recaptcha_check_answer ($privatekey,
                                        $_SERVER["REMOTE_ADDR"],
                                        $_POST["recaptcha_challenge_field"],
                                        $_POST["recaptcha_response_field"]);

        if ($resp->is_valid) {
                echo "You got it!";
        } else {
                # set the error code so that we can display it
                $error = $resp->error;
        }
?>
{/if}
<?php
echo recaptcha_get_html($publickey, $error);
?>
       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

Thanks.

       
flxc4p4str's avatar
flxc4p4str
3 posts
16 years ago
flxc4p4str's avatar flxc4p4str

if anyone is still looking for a reCAPTCHA extension

http://ellislab.com/forums/viewthread/122485/

       
grantmx's avatar
grantmx
1,439 posts
15 years ago
grantmx's avatar grantmx

Komra - I tired your solution on 1.6.8 and it breaks the page. Not sure what is going on. Thanks!

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.