We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38685
    • 59 Posts
    I believe the answers on this topic shows that you don’t get answers, only alternatives....

    Here is what I have so far....

    		# check ReCaptcha
      		if($vericode) {
      		   $CaptchaPath = $modx->config["base_path"].'assets/snippets/recaptcha/'; # Set Captcha Snippet Path 
    		   $privatekey = "--- my private key ------"; # Set Private Key 
    
    		# Set Snippet Paths 
     
    		   require_once($CaptchaPath."recaptchalib.php");
                        
    			$resp = recaptcha_check_answer ($privatekey,  # Check the Recaptcha answer generated in the form 
                                    $_SERVER["REMOTE_ADDR"], $fields["recaptcha_challenge_field"], $fields["recaptcha_response_field"]);
    
      			if ($resp->is_valid) {
    			     return; // echo "Your Captcha just validated!";
    		             } else {
            		        $vMsg[count($vMsg)]= "(reCAPTCHA said: " . $resp->error . ")" . 
                                    "<br />  Please re-select the recipients you wish to send to!";  // This died!
       		  	  }
    		}
    


    And my recaptcha snippet....

    $server = "http://api.recaptcha.net";
            $pubkey = "-- my public key ---";
            $errorpart = "";
            if ($error) {
               $errorpart = "&error=" . $error;
            }
            return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>
    
    	<noscript>
      		<iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
      		<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
      		<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
    	</noscript>';
    



    Getting the correct validation from the function ’recaptcha_check_answer’ is what I need...

    The recaptcha_check_answer function is called from the recaptchalib.php....

    This is the code given to us by reCaptcha for validating it

    # are we submitting the page?
    if ($_POST["submit"]) {
      $resp = recaptcha_check_answer ($privatekey,
                                      $_SERVER["REMOTE_ADDR"],
                                      $_POST["recaptcha_challenge_field"],
                                      $_POST["recaptcha_response_field"]);
    
      if ($resp->is_valid) {
        echo "You got it!";
        # in a real application, you should send an email, create an account, etc
    } else {
    die ("reCAPTCHA failed") , but using the error message is
        # more user friendly
        $error = $resp->error;
    


    Only I don’t know why it doesn’t pass the fields from my snippet [[recaptcha]] to validate in eForm.inc.php!!

    Sorry if I seem to have a bit of a one tracked mind on this one BobRay....
    I am kinda stubborn like that smiley
      Paul AL Bakulich - Association for Computing Machinery Professional Member
      http://palbakulich.me/ | http://twitter.com/#!/palhmbs
      • 3749
      • 24,544 Posts
      Quote from: paulhomebus at Nov 06, 2009, 05:08 AM

      Sorry if I seem to have a bit of a one tracked mind on this one BobRay....
      I am kinda stubborn like that smiley

      So it seems. wink

      Are you sure all the necessary variables are actually set? I’m not sure $_SERVER[’REMOTE_ADDR’] is available with register_globals off.

      I’m not an expert on eForm at all and I’ve never used reCaptcha, so I’m afraid I can’t be much help.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 38685
        • 59 Posts
        Thanks! I will create a chunk to check the $_SERVER[’REMOTE_ADDR’]

        BTW.... Sometimes any dialogue is better than no response at all!!

        BobRay - Thank you for your willingness to help!

        P.S.. I checked using echo $_SERVER[’REMOTE_ADDR’] and it gave me an IP address...
        so I guess it must be the other parts of the code not working....
          Paul AL Bakulich - Association for Computing Machinery Professional Member
          http://palbakulich.me/ | http://twitter.com/#!/palhmbs
          • 18913
          • 654 Posts
          This thread
          http://modxcms.com/forums/index.php?topic=28123.0
          specifically post #18 has some chunk and snippet code that would seem to work. But I haven’t gotten it to run yet. Nor have I successfully adapted the recaptcha-provided code to MODx. I’ve gotten close by adapting eForm, but there’s some logic that I clearly don’t appreciate yet that is tripping me up.

          EDIT : Should have noted that isn’t a fix to work with eForm. But maybe the logic helps.
            • 38685
            • 59 Posts
            I also tried to get this work....
            But failed...
            all I got out of it was a please get your valid API Key from Recaptcha!

              Paul AL Bakulich - Association for Computing Machinery Professional Member
              http://palbakulich.me/ | http://twitter.com/#!/palhmbs
              • 18913
              • 654 Posts
              BTW, on it’s own, outside of eForm, I am able to get reCaptcha to work. Make sure you are calling it *uncached* - when I called the snippet code with "[[" it was not a happy camper. FWIW ....

              Matt
                • 18913
                • 654 Posts
                Okay, I got the chunk and snippet code linked to in the above reply to work. Starting with a fresh install of Evo 1.0.2., I uploaded the recaptchalib.php file to a new subdirectory assets/snippets/recaptcha

                - I created a document called "recaptcha_test_2". Linked to the minimal template, it’s contents are :
                [!recaptcha_snippet_2? &email=`--a valid email addy--` &tpl=`recaptcha_form_2` &captchaLibrary=`assets/snippets/recaptcha/recaptchalib.php` &captchaKeyPublic=`-- my public key --` &captchaKeyPrivate=`--my private key--`!]

                Note that this is an uncacheable call on a cacheable page.

                - I created a chunk called "recaptcha_form_2" and its contents are exactly what is in "enquiryform.chunk.txt" as found in the above referenced thread.

                - I created a snipped called "recaptcha_snippet_2" and its contents are exactly what is in "enquiryform.snippet.txt" as found in the above referenced thread.

                The resulting page looks like crap, but I was looking for "proof of concept" smiley

                With this, I was able to get error messages back for incorrect entries. For correct entries I was given a "success" message.

                To get the example code provided with the recaptcha library to work - again, outside of eForm - I similarly created a test document which makes a call to {{recaptcha_chunk}}. This chunk is
                <html>
                  <body>
                    <form action="" method="post">
                    [!recaptcha_snippet!]
                    <br/>
                    <input type="submit" value="submit" />
                    </form>
                  </body>
                </html>


                Again, this is an uncached call.

                The code in "recaptcha_snippet" is exactly the PHP that is found in the example embedded in that HTML.

                Needless to say, if I can get my head around eForm’s approach and get this incorporated, I’ll post it. As I mentioned, attempts so far haven’t worked out and it may just be something simple I’m overlooking....

                Hope this helps,
                Matt
                  • 38685
                  • 59 Posts
                  The attached file is where I am at with this....
                  it contains an updated eform.inc.txt which is a .php
                  & and the recaptchalib.txt which is the .php
                  Just change the extensions!

                  BTW you need a ’live’ site to test & a recaptcha public & private key!

                  I still have no answer or solution, but....
                  I have integrated all the best suggestions, just look and see....

                  I have even asked ReCaptcha’s support people if they could help me on this.... LOL!
                  as I am pretty much at my wits end!

                  This version is very close to working....
                  but doesn’t validate....
                  & I know all the correct variables are going into the Recaptcha library cause I have debugged it!

                    Paul AL Bakulich - Association for Computing Machinery Professional Member
                    http://palbakulich.me/ | http://twitter.com/#!/palhmbs
                    • 18913
                    • 654 Posts
                    Hi,
                    Thanks for the above. What does your eForm call look like? Can you post the code to the form(s) you are using?
                    Matt
                      • 38685
                      • 59 Posts
                      Hi Matt....

                      This uses the &vericode=`1` function that is already set up....
                      so a snippet call would look like....

                      <script type=\"text/javascript\">
                      			var RecaptchaOptions = {
                      			   theme : 'custom'
                        custom_theme_widget: 'recaptcha_widget'	}; </script>
                      [!echeckField!]
                      [!eForm? &formid=`your form id` &subject=`subject` &tpl=`your template` &ccsender=`1` &eFormOnValidate=`checkField` &vericode=`1` &report=`your reportfom` &thankyou=`your thanks form` !]  


                      As you’ll probably know if you have a vericode you just insert [+vericode+] container into your form and viola! Your ReCaptcha should turn up....

                      Now it will only validate IF and only IF you have &eFormOnValidate=`checkField` set.... the echeckField snippet loooks like this....
                      function checkField(&$fields,&$vMsg,&$rMsg) {
                              if(!empty($fields['Name2'])) {
                                 return false; 
                           }  else {
                             return;			
                        }
                      }
                      


                      of course I have an empty hidden with css field.... like this

                      <input class="fun" type="text" name="Name2" maxlength="75" size="40" /></p>

                      and my css looks like this to run both the hiding of the recaptcha script (which produces it’s own Recaptcha) and the above input!

                      
                      /********** Captcha Styling **********/
                      #divrecaptcha{  
                       	font-size:13px; 
                       	font-family: Verdana, helvetica, sans-serif;  
                          	text-align:right;
                      }
                      #divrecaptcha controls{  
                      	width: 170px;
                       	font-size:10px; 
                       	font-family: Verdana, helvetica, sans-serif;  
                      }    
                      #recaptcha_image{
                      	background:#f9f9f9;  
                          	border:1px solid #e0e0e0;
                          	width: 250px;
                      	margin-top: 20px;
                      	float:right;
                      }  
                      #recaptcha_response_field {
                      	width:300px;
                      	border:1.5px solid #9898F1;
                      	font:14px Verdana, helvetica, sans-serif;
                      	color: Black;
                      	font-weight:bold;
                      	margin-top: 20px;
                      }  
                      #divrecaptchalogo {
                      	background:#fff url(images/recaptcha.gif);
                      	height: 86px;
                      	width: 161px;
                      	float: left;
                      }
                      #divrecaptcha a{  
                      	font-size:10px;    
                      	font-family:Verdana, helvetica, sans-serif; 
                      	text-decoration:none;
                      	color:#3366ff;  
                      }  
                      #divrecaptcha a:hover{  
                           	color:#333; 
                      	text-decoration:underline;  
                      }  
                      #divhidecaptcha {
                      	position:absolute;
                      	left:-100px;
                      	top:-200px;
                      	width:1px;
                      	height:1px;
                      	overflow:hidden;
                      }
                      .fun {
                      	position:absolute;
                      	text-decoration:underline;
                      	background-color:#CC0000;
                      	left:0px;
                      	top:-500px;
                      	width:1px;
                      	height:1px;
                      	overflow:hidden;
                      }
                      


                      Thanks again Matt for your interest!
                        Paul AL Bakulich - Association for Computing Machinery Professional Member
                        http://palbakulich.me/ | http://twitter.com/#!/palhmbs