reCAPTCHA is a nice service that usually added to a registration form and helps prevent bots from registering automatically. The service usually displays a small and easy challenge to a human but which would be difficult for a bot to answer. In this blog post we are going to show you how to add reCAPTCHA to an Ionic app.
- Create a new Ionic app based on
- Go to https://github.com/vividcortex/angular-recaptcha, download
vcRecaptcha.js, and unzip the file.
- Inside the App Builder, go
Upload from fileand select the
angular-recaptcha.jsfile from your drive. For
Angular moduleand click
- Now, open
Screen1and add an
HTMLcomponent to the page.
- Under the
Editand add the following code:
1<div vc-recaptcha key="'XXXXXXXX'" on-success="onSuccess()"></div>
'XXXXXXXXX'is the key generated on https://www.google.com/recaptcha/admin (your key must be inside the double quotes).
- Switch to
Scopeview and add a new function, name it
onSuccess, and add the following code to the editor:
onSuccess()is the scope function that executes when the correct Captcha is entered (here, another page will open).
- To demonstrate this, create a new page and name it
Success. Add a
Textcomponent to the page and paste
- Also, if you want to add a solving annotating images to your reCaptcha, go to
Project > Routing, click
Screen1, and check
That’s it. You are ready to test your app with the reCAPTCHA.
Looking for more examples? Check out our sample apps list. Every app has preconfigured app UI and app backend for you to try.