Using captcha validation in external form controller

Permalink
I'm bit at lost of how to verify the captcha within an external controller. I assume I have to load the helper, when using the form it returns: "Class 'Application\Block\ExternalForm\Form\Controller\Core' not found". Without loading the helper it returns. "Call to a member function check() on a non-object". I'm not sure how to make use of this other controller like the default form does.

Snippet below:

namespace Application\Block\ExternalForm\Form\Controller;
use Concrete\Core\Controller\AbstractController;
class Subscribe extends AbstractController
{
  static $handled = false;
  public function action_response($bID) {
    if (static::$handled) {
      return;
    }
    $captcha = Core::make('helper/validation/captcha');
    if(!$captcha->check($_POST["ccmCaptchaCode"])) {
      $this->set('response', t('<div class="alert alert-danger"><b>Error: Subscription not added.</b><br> Captcha is incorrect.</div>'));
      return;
    }
    static::$handled = true;


Thanks in advance.

 
hutman replied on at Permalink Best Answer Reply
hutman
You're missing the use statement at the top. You need to add

use Core;
admin replied on at Permalink Reply
Thanks - I need to read up about the backend more.

Works somewhat, although it seems all captcha responses are returned with false. Any clue as to why that is happening? I assume there must be a way to output the securimage as to compare if it is changing in anyway.

http://documentation.concrete5.org/api/source-class-Concrete.Core.C...
hutman replied on at Permalink Reply
hutman
For some reason External Forms have the submit function called twice (this was the case in 5.7 and I don't believe it was fixed in 5.8) so you need to make sure you are redirecting after the first submission, otherwise on the second submission the captcha is always going to be false.

There could be other things that can be improved with the workflow but I don't know what you're doing on your form as you've only included the controller code.