Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
reCaptcha / Captcha - Working or not?
  • Hi,

    I downloaded and am using the reCaptcha package from: https://github.com/carlcraig/fuel-captcha

    Seems like i hve it all working (i see the captcha field in my form), but there is no check happening on the it.
    In my controller where the form gets submitted to, it always shows as true/blank

            if (Input::method() == 'POST')  {
                 echo 'this is captcha: '.Captcha::forge('recaptcha')->check() == true ? 'This is true' : 'falze';
            }

    no matter what I enter in the input boxes.

    Has anyone gotten this working correctly or do it still wrk with the current version of fuel?

    Thanks.
  • Not checked at the moment, I'll have a look this evening (I need it for a personal project).
    Stay tuned
  • It's really weird. I cant even force a true response from the 'check()'
    I must be doing something wrong.
  • OK, so I changed the line:
    echo 'this is captcha: '.Captcha::forge('recaptcha')->check() == true ? 'This is true' : 'falze';

    to:

    $captchaCheck = Captcha::forge('recaptcha')->check() ? 'This is true' : 'falze';
    echo $captchaCheck;

    and everything works fine.

    Now I just need to get the error to show up.
  • yeah.. I'm just stuck on the error now...

    In the controller, I have

            if (Input::method() == 'POST')
            {
                            $captcha = Captcha::forge('recaptcha');
                           
                            if (!$captcha->check()) {
                                $this->template->content->captchaMsg = $captcha->error();
                            } else {
                                $this->template->content->captchaMsg = 'Success';
                            }
                            ................
             }


    and in view
                            echo Captcha::forge('recaptcha')->html(null, 'Error Msg');
                            echo @$captchaMsg;

    I'm expecting the $captchaMsg tp be 'Error Msg' when it's submitted and an error is thrown.

    Maybe I'm misunderstanding the process as to what it supposed to happen. I think I am supposed to be able to pass
  • I have added exceptions and the response comes back and succeeded and end up in the 'true' part of the check(), but then on the controller side where it's looking for this, it doesnt return anything seems to be empty.  If i replace the 'return true' with 'return "Success";' the response shows 'Success' on the check().

    Is there something in Fuel that handles booleans coming from a package differently or something?
     
  • OK, i think I have this working now....

    I had reverted what I was doing to:
    $captcha = Captcha::forge('recaptcha');
    and then trying:

                            if ($captcha ->check()) {
                                $this->template->content->captchaMsg = $captcha ->check();
                            } else {
                                $this->template->content->captchaMsg = $captcha->error();
                            }

    but never getting a value back It was always false.

    When I changed to this:

                        $capCheck = false;
                        $capCheck = $captcha->check();
                            if ($capCheck) {
                                $this->template->content->captchaMsg = $capCheck;
                            } else {
                                $this->template->content->captchaMsg = $captcha->error();
                            }
    It all works.
  • HarroHarro
    Accepted Answer
    Seems like you can't call the check() method twice.

    Other then it will call the recaptcha service twice, I don't see an immediate reason why that wouldn't work.
  • thinking about it now that you say it makes sense. I guess i was thinking of this as a function of the same information on a single object, but within this method it does do the POST, so yes, it would fail the second time.

    this one threw me.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion