im trying to implement recaptcha2 in angular but i dont know where i put the step 3 in my code https://www.npmjs.com/package/angular-google-recaptcha im creating a form that need this,here's where i put the captcha:
<div class="form-group-log text-center but-form">
<div class="g-recaptcha" data-sitekey="" data-callback="enableButtonEnviar">
</div>
<button type="submit" disabled="disabled" class="btn btn-outline-primary btn-block btn-w-240 " id="Btn-enviar" data-dismiss="modal">
Entrar
</button>
</div>
but doesnt display nothing. in the link says that i need to put this but i dont know where, if i put it in my login.ts only shows the captcha
import { Component } from '@angular/core';
@Component({
selector: 'app',
template: `
<recaptcha
[(ngModel)]="myRecaptcha"
(scriptLoad)="onScriptLoad()"
(scriptError)="onScriptError()"
></recaptcha>
`
})
export class AppComponent {
myRecaptcha: boolean
onScriptLoad() {
console.log('Google reCAPTCHA loaded and is ready for use!')
}
onScriptError() {
console.log('Something went long when loading the Google reCAPTCHA')
}
}
Below implementation gives more in detail and to verify the captcha response is the success on the server side.
In a template-driven form, add a reference to your recaptcha element.
Now pass the recaptcha ref to your form. In my case. It look like below.
In forgot.component.ts
The getResponse() will return a token, which can be verified if the form is submitted from your site as below.
The above call will return the status if the request is actually made from your site and by a user.
Hope it is useful.
Step3 explains using Reactive Form and Template Driven Form.
In Reactive Form (inside component)
In Template:
You can add this code
Same is applicable for Template Driven Form.