Josh Mc
Josh Mc

Reputation: 10244

How do I implement ReCaptcha in a Single Page Application (SPA)

I have a Single Page Application (SPA) I would like to add ReCaptcha to. This application is hosted using IIS as flat Html, Css & Javascript, this SPA in turn talks to a separate REST server (using CORS) for all dynamic content.

The REST server is written using ASP.net WebAPI. The problem is; all examples I have seen of ReCaptcha all use ASP.net MVC (or other languages) to inject html into the webpage, I cannot modify the webpage using ASP.net in this manor. Hopefully someone else has had the same problem.

I am really looking for some 2 parts, first the HTML that belongs on the client, and secondly the Controller that would be on the REST Server to verify with google. Even if this is in another language that I can convert, this will be useful!

Upvotes: 8

Views: 9003

Answers (2)

Shweta Kumari
Shweta Kumari

Reputation: 19

I have used ngx-captcha with my angular project. Here's how I kept my submit button disabled until recaptcha checkbox is checked.

   //code
 <ngx-recaptcha2 (success)="handleSuccess($event)"   #captchaElem [siteKey]="siteKey" formControlName="recaptcha">
                </ngx-recaptcha2>

once captcha is filled , it emits a success event , so use it in a method to make a variable true/false based on which you can enable/disable submit button

Upvotes: 0

Josh Mc
Josh Mc

Reputation: 10244

Looks like what I wanted was simply to use reCaptcha without plugins (https://developers.google.com/recaptcha/docs/display)

Upvotes: 3

Related Questions