Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Config/Recaptcha on release since v2.0.0 #10

Closed
ajimsofwan opened this issue Jul 4, 2023 · 2 comments
Closed

How to use Config/Recaptcha on release since v2.0.0 #10

ajimsofwan opened this issue Jul 4, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@ajimsofwan
Copy link

Argument 1 passed to PHPDevsr\Recaptcha\Recaptcha::__construct() must be an instance of PHPDevsr\Recaptcha\Config\Recaptcha or null

Can't use
use Config\Recaptcha as RecaptchaConfig;
For now i'm using this
use PHPDevsr\Recaptcha\Config\Recaptcha as RecaptchaConfig;

@ddevsr
Copy link
Contributor

ddevsr commented Sep 20, 2023

@ajimsofwan I already push to repo to fix this, before release on v2.0.0

try

composer require phpdevsr/recaptcha-codeigniter4:dev-dev

Now can use helper for getWidget(), getScriptTag() and verifyResponse()

<?php

namespace App\Controllers;

class Home extends BaseController
{
    public function index(): string
    {
        helper('recaptcha');

        $data = [
            'scriptTag' => getScriptTag(),
            'widgetTag' => getWidget(),
        ];

        $captcha = $this->request->getPost('g-recaptcha-response');
        $response = verifyResponse($captcha);

        if (isset($response['success']) and $response['success'] === true) {
            echo "You got it!";
        }

        return view('welcome_message', $data);
    }
}

image
I have tested using helper

@ddevsr ddevsr pinned this issue Sep 20, 2023
@ddevsr ddevsr changed the title Can't use /Config/Recaptcha.php How to use Config/Recaptcha on release since v2.0.0 Sep 20, 2023
@ddevsr ddevsr changed the title How to use Config/Recaptcha on release since v2.0.0 How to use Config/Recaptcha on release since v2.0.0 Sep 20, 2023
@ddevsr
Copy link
Contributor

ddevsr commented Sep 20, 2023

Or you can use service('recaptcha')

$recaptcha = service('recaptcha');

$recaptcha->getScriptTag(); // For script tag
$recaptcha->getWidget(); // For widget
$recaptcha->verifyResponse($response); // For verify

@ddevsr ddevsr added the bug Something isn't working label Sep 21, 2023
@ddevsr ddevsr closed this as completed Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants