2.3.1 • Published 4 months ago

ng-hcaptcha v2.3.1

Weekly downloads
389
License
MIT
Repository
github
Last release
4 months ago

GitHub license  GitHub issues  GitHub pull-requests

ng-hcaptcha - hCaptcha Component for Angular

ng-hcaptcha provides an easy to use component for hCaptcha.

Table of Contents

Supported Angular versions

The latest version of ng-hcaptcha currently supports Angular v9 to v17.

Installation

Step 1 - Install the ng-hcaptcha dependency

# NPM
npm install --save ng-hcaptcha

# Yarn
yarn add ng-hcaptcha

You can use the tag 'next' to get the latest beta version.

Step 2 - Import the NgHcaptchaModule

import { NgHcaptchaModule } from 'ng-hcaptcha';

@NgModule({
    imports: [
        // Option #1
        // Set the sitekey globally for every hCaptcha component
        NgHcaptchaModule.forRoot({
            siteKey: 'YOUR_SITEKEY',
            languageCode: 'de' // optional, will default to browser language
        }),

        // Option #2
        // This option requires you to set the [siteKey] property for every hCaptcha component
        NgHcaptchaModule.forRoot()
    ]
})

Usage

Template:

<!-- Regular usage -->
<ng-hcaptcha (verify)="onVerify($event)"
              (expired)="onExpired($event)"
              (error)="onError($event)">
</ng-hcaptcha>

<!-- Usage in forms -->
<!-- The value of the form control will be the verification token -->
<form [formGroup]="formGroup" (submit)="onSubmit()">
    <ng-hcaptcha formControlName="captcha"></ng-hcaptcha>
</form>

<!-- Invisible captcha -->
<button ngHcaptchaInvisibleButton
        (verify)="onVerify($event)"
        (expired)="onExpired($event)"
        (error)="onError($event)">Click me</button>

TS:

onVerify(token: string) {
    // The verification process was successful.
    // You can verify the token on your server now.
}

onExpired(response: any) {
    // The verification expired.
}

onError(error: any) {
    // An error occured during the verification process.
}

Execute hCaptcha programmatically

The hCaptcha verification process can also be executed programmatically:

@Component({
  selector: 'hc-programmatically',
  templateUrl: './programmatically.component.html',
  styleUrls: ['./programmatically.component.scss']
})
export class ProgrammaticallyComponent {

  constructor(private hcaptchaService: NgHcaptchaService) { }

  verify() {
    this.hcaptchaService.verify().subscribe(
      (result) => {
        console.log('SUCCESS', result);
      },
      (err) => {
        console.log('FAILED', err);
      },
      () => {
        console.log('COMPLETE');
      }
    );
  }

}

Properties

The properties below exist for all captcha components.

siteKey Allows you to set the site key per captcha instance.

languageCode Allows you to force a specific language. See https://docs.hcaptcha.com/languages

Bugs? Ideas?

If you found a bug or something you don't like, feel free to open an issue. If you have any ideas for new features or improvements, feel free to contribute or open an issue :wink:

Support me

If you would like to support me for free, just create your hCaptcha account using my referral link :relaxed: https://hCaptcha.com/?r=4afcb2d42338

2.3.0

4 months ago

2.3.1

4 months ago

2.2.0

12 months ago

2.1.0

1 year ago

2.0.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

3 years ago

1.0.0

3 years ago

1.0.0-beta.5

3 years ago

1.0.0-beta.3

4 years ago

1.0.0-beta.2

4 years ago

1.0.0-beta.1

4 years ago

1.0.0-beta.0

4 years ago

0.1.0-beta.3

5 years ago

0.1.0-beta.2

5 years ago

0.1.0-beta.1

5 years ago

0.1.0-beta.0

6 years ago

0.0.1

6 years ago