We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36924 ☆ A M B ☆
    • 298 Posts
    I love the Captcha extra created by BobRay. The math embeded on the image is superior to the text format in use in formit math hook.

    i will like suggestion or help in making the Captcha work on frontend forms (like it does for the manager login).

    Thank you.
      • 3749
      • 24,544 Posts
      In theory, you can use Captcha anywhere.

      The Captcha code will produce an image and write the correct answer to a $_SESSION variable:

      [[!CaptchaImage]]
      

      <?php
      /* CaptchaImage snippet code */
      $captchaImage = <a href="'.$_SERVER['PHP_SELF'].'" class="loginCaptcha"><img src="'.$modx->getOption('site_url').'assets/components/captcha/captcha.php?rand='.rand().'" alt="'.$alt.'" /></a>


      The output is controlled by the System Settings in the captcha namespace, most of which can (IIRC) be overridden by properties in the snippet tag.

      Then, in the snippet or hook that processes the submission, something like this (untested):

       
              $rt = true;
              $modx->lexicon->load('captcha:default');
              if ($modx->getOption('captcha.enabled',null,true)) {
                  if (!isset ($_SESSION['veriword'])) {
                       $rt = false;
                       $modx->setPlaceholder('error', '$_SESSION Variable not set');
      
      
                  }  else if ($_SESSION['veriword'] != $_POST['captcha_code']) {
                      $rt = false;
                      if ($modx->getOption('captcha.use_mathstring',null,true)) {
                          $modx->setPlaceholder('error', $modx->lexicon('login_mathstring_error'));
                      } else {
                          $modx->setPlaceholder('error', $modx->lexicon('login_captcha_error'));
                      }
                  }
              }
              return $rt;
      
      
        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
        • 36924 ☆ A M B ☆
        • 298 Posts
        Thank you Bob. Very clear, seems would work without issues. Will update this thread asap.
          • 43957
          • 79 Posts
          I would love to see this available with FormIt integration. My rooky PHP coding is holding me back.

          ;-D
            • 36549
            • 572 Posts
            Hi,

            I realise this is an old thread but I'm trying to get Captcha to work with Formit too but I am not familiar with PHP. Googles Recaptcha no longer works on one site of mine so I need to implement something else.
            I have the Captcha displaying on the front-end just by adding the following but how do I generate an error message and get the actual Captcha to require input (I'm sure it must be pretty simple so apologies if i'm missing the obvious):
            <li>
            <label>Word Verification:<span class="required">*</span></label>
            <img src="[[++assets_url]]components/captcha/captcha.php" alt="Captcha Image" />
            </li>


            Thanks for any help
              www.9thwave.co.uk
                 WEB | DESIGN | PRINT
              • 3749
              • 24,544 Posts
              You need an input field for the CAPTCHA response and you need to tell FormIt that it's required.

              As an alternative, you could add a bit of JavaScript code that will pop up an error alert and prevent the form from being submitted if that field is empty.
                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
                • 36549
                • 572 Posts
                Thanks for your reply BobRay. I'm using the FormIt math hook for now which seems to be working OK.
                  www.9thwave.co.uk
                     WEB | DESIGN | PRINT
                  • 3749
                  • 24,544 Posts
                  The math hook is probably more secure than CAPTCHA.
                    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