So I’ve been using reCAPTCHA newer version (2.0) with yii and I haven’t found any discussion to this topic yet, instead of the older version where you can find it in reCAPTCHA 1.3 Extension.
reCAPTCHA is a free service provided by Google that protects your site from spam and abuse. The reCAPTCHA 2.0 is the newer version of reCAPTCHA developed by Google.
In this version, we don’t have to download any extension code or module. We can easily render the widget by calling the google reCAPTCHA api.js in our view.
To use it in your site, you need to have valid site key and secret key for it. You can get them by registering yourself at https://www.google.com/recaptcha
Current Version: 2.0
Resources
-
reCAPTCHA
-
Join Discussion
[size="5"]Documentation[/size]
Requirements
- Yii 1.1 or above
Usage
Make sure you have your site key and secret key from Google reCAPTCHA
The easiest method for rendering the reCAPTCHA widget on your page is to include the necessary JavaScript resource and a g-recaptcha tag. The g-recaptcha tag is a DIV element with class name ‘g-recaptcha’ and your site key in the data-sitekey attribute.
In the view:
Put this script code before/after your form:
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
It will automatically calls the JavaScript from Google through the internet.
Next, to display the widget you have to put this code inside your form:
<form>
..
<div class="g-recaptcha" data-sitekey="your_site_key"></div>
..
</form>
Your widget will be displayed when you open your page.
If you want to explicitly render the widget (to use callback etc) you can find the documentation provided by Google in this link