Yii Framework Forum: reCAPTCHA 2.0 - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

reCAPTCHA 2.0 Google reCAPTCHA 2.0 validator

#1 User is offline   azzafirdaus 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 24-April 15
  • Location:Indonesia

Posted 10 March 2016 - 05:41 AM

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



Documentation

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
0

#2 User is offline   Yuri! 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 44
  • Joined: 30-December 10

Posted 26 May 2016 - 11:05 AM

I have used this extension, works fine.
0

#3 User is offline   Giordano 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 07-March 10

Posted 13 March 2017 - 07:44 AM

Thanks Yuri, for pointing us to the reCaptcha API 2 extension (https://github.com/d...ng/yiiReCaptcha).

It looks very promising but we cannot get it to work running Yii1. The error we get on a Mac running MAMP is:

Fatal error: Cannot redeclare class ReCaptcha in /Users/buddy/Documents/MAMPROOT/mysite.com/protected/extensions/yiiReCaptcha/ReCaptcha.php on line 294

This is in the config main.php

'reCaptcha' => array(
'name' => 'reCaptcha',
'class' => 'application\extensions\yiiReCaptcha\ReCaptcha',
'key' => '<our_key>',
'secret' => '<our_secret>',
),


This is in the formModel:

public function rules()
{
return array(
array('verifyCode', 'required'),
array('verifyCode', 'application.extensions.yiiReCaptcha.ReCaptchaValidator'),
);
}


And the view:

<?php
$this->widget('application.extensions.yiiReCaptcha.ReCaptcha', array(
'model' => $model,
'attribute' => 'verifyCode',
));
?>


Any suggestions are very welcome indeed!

Cheers,
Giordano
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

3 User(s) are reading this topic
0 members, 3 guests, 0 anonymous users