We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43592
    • 97 Posts
    Im getting crazy on this recaptcha stuff:

    I have my form hook
    [[!FormIt?
       &hooks=`myrecaptcha2,spam,email,redirect`
       &emailTpl=`tpl_kontakt`
       &emailTo=`[[!getmaildata]]`
    &emailBCC=`[[+fi.email]]`
    &emailSubject=`Nachricht an Sie über stroemen.org`
       &redirectTo=`41`
       &validate=`nachname:required,
          email:email:required,
          nachricht:required:stripTags`
    
    ]]


    and an exactly so called inline snipped called "myrecaptcha2"

    <?php
    include MODX_CORE_PATH.'components/recaptchav2/model/recaptchav2/ReCaptcha/ReCaptcha.php';
    $recaptcha = new \ReCaptcha\ReCaptcha("6L..."); //secretcode-numbers
    $modx->log(modX::LOG_LEVEL_ERROR, 'Hello'); //testing log
     
    if (empty($recaptcha) || (! $recaptcha instanceof \ReCaptcha\Recaptcha)) {
       $modx->log(modX::LOG_LEVEL_ERROR, '[recaptcha2] Instantiation failed');
       return '';
    }
     
    $resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp);
    if ($resp->isSuccess()) {
        // verified!
    } else {
        $errors = $resp->getErrorCodes();
        return false;
    }
    
    return true;
    


    Isnt that a sign, that the snippet isnt even found because I get nothing out of the LOG-protocoll
      • 3749
      • 24,544 Posts
      Try this at the top:

      $file = MODX_CORE_PATH.'components/recaptchav2/model/recaptchav2/ReCaptcha/ReCaptcha.php';
      if (!file_exists($file)) {
         $modx->log(modX::LOG_LEVEL_ERROR, 'File does not exist: ' . $file);
      }



      Also, if that file is there, look inside it and make sure it contains the definition of the ReCaptcha class (and check the exact spelling of the class name).

      Another possibility is an issue with case-sensitivity in the file name. If the file is recaptcha.php, including it with ReCaptcha.php won't work.
        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
        • 43592
        • 97 Posts
        <?php
        $file = MODX_CORE_PATH.'components/recaptchav2/model/recaptchav2/ReCaptcha/ReCaptcha.php';
        if (!file_exists($file)) {
           $modx->log(modX::LOG_LEVEL_ERROR, 'File does not exist: ' . $file);
        }
        else
        {
         $modx->log(modX::LOG_LEVEL_ERROR, 'File does exist: ' . $file);
        }
        $recaptcha = new \ReCaptcha\ReCaptcha("6LeJKxsTAAAAADIqvvz1UhipgtEeFNZLA4a7cgEV"); //secretcode-numbers
        
        if (empty($recaptcha) || (! $recaptcha instanceof \ReCaptcha\Recaptcha)) {
           $modx->log(modX::LOG_LEVEL_ERROR, '[recaptcha2] Instantiation failed');
           return '';
        }
         
        $resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp);
        if ($resp->isSuccess()) {
            // verified!
        } else {
            $errors = $resp->getErrorCodes();
            return false;
        }
        
        return true;


        I get the Log information now, that the File does exist, and the Namespace and Class name are spelled correctly.
        But still I have that server error.
        • Quote from: sspind at Apr 06, 2016, 07:49 AM
          Hi forum members,

          Because of sepiarivers recaptcha2 beta-plugin doesnt work at all for me on Formit etc.


          Have you tried the latest version 2.0.2?

          The ReCaptcha class from Google previously used file_get_contents and now it's updated to use cURL. The latest is in the Extras repo here: http://modx.com/extras/package/recaptchav2

          The important bit is that in your Snippet, the ReCaptcha class is instantiated like this:
          $recaptchav2 = new \ReCaptcha\ReCaptcha($secret, new \ReCaptcha\RequestMethod\CurlPost());
          


          ...passing in their new CurlPost request class as the 2nd argument. (You should do this if using your own snippet as well)
            [sepiariver.com] (https://sepiariver.com/)
            • 43592
            • 97 Posts
            Thank you Sepia River,

            I tried your Package half a day but didnt get it to work. (see issue on github).

            Additional info:
            I still depend on the package by "instatizing" it as you see.
            Also the ReCaptcah API.js link is in my template, otherwise it wouldn't show up.
            I get no log level error for Instantiation failed.

            Now I have

            <?php
            $file = MODX_CORE_PATH.'components/recaptchav2/model/recaptchav2/ReCaptcha/ReCaptcha.php';
            if (!file_exists($file)) {
               $modx->log(modX::LOG_LEVEL_ERROR, 'File does not exist: ' . $file);
            }
            else
            {
             $modx->log(modX::LOG_LEVEL_ERROR, 'File does exist: ' . $file);
            }
            
            $recaptchav2 = new \ReCaptcha\ReCaptcha("6Le..", new \ReCaptcha\RequestMethod\CurlPost()); //secretcode-numbers
            
            
            if (empty($recaptcha2) || (! $recaptcha2 instanceof \ReCaptcha\Recaptcha)) {
               $modx->log(modX::LOG_LEVEL_ERROR, '[recaptcha2] Instantiation failed');
               return '';
            }
             
            $resp = $recaptcha2->verify($gRecaptchaResponse, $remoteIp);
            if ($resp->isSuccess()) {
                // verified!
            } else {
                $errors = $resp->getErrorCodes();
                return false;
            }
            
            return true;
            
              • 43592
              • 97 Posts
              Dear Forum members,

              any suggestions?

              Im still in trouble with this ..

              Thank you!
              • Quote from: sspind at Apr 14, 2016, 05:34 AM
                Thank you Sepia River,

                I tried your Package half a day but didnt get it to work. (see issue on github).

                I checked but the only open issue is about front-end validation. That's not the issue you're experiencing, if I understand correctly?


                Additional info:
                I still depend on the package by "instatizing" it as you see.

                Have you tried calling the class like this?
                // Get the class
                $recaptchav2Path = $modx->getOption('recaptchav2.core_path', null, $modx->getOption('core_path') . 'components/recaptchav2/');
                $recaptchav2Path .= 'model/recaptchav2/';
                if (!file_exists($recaptchav2Path . 'autoload.php')) {
                    $modx->log(modX::LOG_LEVEL_WARN, 'Cannot find required RecaptchaV2 autoload.php file.'); 
                    return false;
                }
                require_once($recaptchav2Path . 'autoload.php');
                $recaptchav2 = new \ReCaptcha\ReCaptcha($secret, new \ReCaptcha\RequestMethod\CurlPost());
                if (!($recaptchav2 instanceof \ReCaptcha\ReCaptcha)) {
                    $hook->addError('recaptchav2_error', $tech_err_msg);
                    $modx->log(modX::LOG_LEVEL_WARN, 'Failed to load recaptchav2 class.'); 
                    return false;
                }
                



                Also the ReCaptcah API.js link is in my template, otherwise it wouldn't show up.

                Usually that's taken care of with the "recaptchav2_render" Snippet which calls the Chunk "recaptchav2_html"

                Are you in the Community Slack? If you private message me @sepiariver and can provide me with some access to your site, I can help you more directly.
                  [sepiariver.com] (https://sepiariver.com/)