Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Upgrade to be 3.0 compatible.

  • Loading branch information...
commit 985ebbf070fc678140f63c6bc0889154d1f57dd8 1 parent 8c71aba
@robert-h-curry robert-h-curry authored
View
10 README.md
@@ -12,7 +12,7 @@ by giving them a challenge to decrypt an image.
## Requirements
- * SilverStripe 2.3 or newer
+ * SilverStripe 3.0.0 or newer
* curl PHP module
* Requires [SpamProtectionModule](http://silverstripe.org/spam-protection-module/)
@@ -26,15 +26,13 @@ by giving them a challenge to decrypt an image.
* Copy the `recaptcha` directory into your main SilverStripe webroot
* Run ?flush=1
-This should go in your `mysite/_config.php`. You can get an free API key at [http://recaptcha.net/api/getkey](recatcha.net).
+This should go in your `mysite/_config.php`. You can get an free API key at [http://www.google.com/recaptcha](https://www.google.com/recaptcha/admin/create)
RecaptchaField::$public_api_key = '<publickey>';
RecaptchaField::$private_api_key = '<privatekey>';
-
## Usage
-
### As a Standalone Field
If you want to use Recaptcha field by itself, you can simply just include it as a field in your form.
@@ -42,7 +40,7 @@ If you want to use Recaptcha field by itself, you can simply just include it as
$recaptchaField = new RecaptchaField('MyCaptcha');
$recaptchaField->jsOptions = array('theme' => 'clean'); // optional
-See [http://recaptcha.net/apidocs/captcha/](Recaptcha API docs) for more configuration options.
+See [Recaptcha API docs](https://developers.google.com/recaptcha/intro) for more configuration options.
### Integration with Spamprotection module
@@ -50,7 +48,7 @@ This requires the [[:modules:spamprotection|spamprotection module]] to be instal
Configuration example in `mysite/_config.php`
- SpamProtectorManager::set_spam_protector("RecaptchaProtector");
+ SpamProtectorManager::set_spam_protector('RecaptchaProtector');
Then once you have setup this config you will need to include the spam protector field as per the instructions on the [[modules:spamprotection|spamprotection module]] page.
View
17 code/RecaptchaField.php
@@ -124,8 +124,8 @@ class RecaptchaField extends SpamProtectorField {
'tr',
);
- function __construct($name, $title = null, $value = null, $form = null, $rightTitle = null) {
- parent::__construct($name, $title, $value, $form, $rightTitle);
+ function __construct($name, $title = null, $value = null) {
+ parent::__construct($name, $title, $value);
$this->jsOptions = self::$js_options;
@@ -148,9 +148,9 @@ public function Field($properties=array()) {
. "var RecaptchaOptions = " . $this->getJsOptionsString()
. "//]]></script>";
}
-
- $previousError = Session::get("FormField.{$this->form->FormName()}.{$this->Name()}.error");
- Session::clear("FormField.{$this->form->FormName()}.{$this->Name()}.error");
+
+ $previousError = Session::get("FormField.{$this->form->FormName()}.{$this->getName()}.error");
+ Session::clear("FormField.{$this->form->FormName()}.{$this->getName()}.error");
// iframe (fallback)
$iframeURL = ($this->useSSL) ? 'https://' : 'http://';
@@ -171,7 +171,7 @@ public function Field($properties=array()) {
<script type="text/javascript">
//<![CDATA[
Recaptcha.create("' . self::$public_api_key . '",
- "' . $this->Name() . '", {
+ "' . $this->getName() . '", {
callback: Recaptcha.focus_response_field
});
//]]>
@@ -251,7 +251,6 @@ public function validate($validator) {
_t(
'RecaptchaField.EMPTY',
"Please answer the captcha question",
- PR_MEDIUM,
"Recaptcha (http://recaptcha.net) provides two words in an image, and expects a user to type them in a textfield"
),
"validation",
@@ -268,7 +267,6 @@ public function validate($validator) {
_t(
'RecaptchaField.NORESPONSE',
"The recaptcha service gave no response. Please try again later.",
- PR_MEDIUM,
"Recaptcha (http://recaptcha.net) provides two words in an image, and expects a user to type them in a textfield"
),
"validation",
@@ -289,13 +287,12 @@ public function validate($validator) {
} else {
// Internal error-string returned by recaptcha, e.g. "incorrect-captcha-sol".
// Used to generate the new iframe-url/js-url after form-refresh.
- Session::set("FormField.{$this->form->FormName()}.{$this->Name()}.error", trim($error));
+ Session::set("FormField.{$this->form->FormName()}.{$this->getName()}.error", trim($error));
$validator->validationError(
$this->name,
_t(
'RecaptchaField.VALIDSOLUTION',
"Your answer didn't match the captcha words, please try again",
- PR_MEDIUM,
"Recaptcha (http://recaptcha.net) provides two words in an image, and expects a user to type them in a textfield"
),
"validation",
View
5 lang/en.yml
@@ -0,0 +1,5 @@
+en:
+ RecaptchaField:
+ EMPTY: Please answer the captcha question
+ VALIDSOLUTION: Your answer didn't match the captcha words, please try again.
+ NORESPONSE: The recaptcha service gave no response. Please try again later.
View
16 lang/en_US.php
@@ -1,16 +0,0 @@
-<?php
-
-global $lang;
-
-$lang['en_US']['RecaptchaField']['EMPTY'] = array(
- 'Please answer the captcha question',
- PR_MEDIUM,
- 'Recaptcha (http://recaptcha.net) provides two words in an image, and expects a user to type them in a textfield'
-);
-$lang['en_US']['RecaptchaField']['VALIDSOLUTION'] = array(
- 'Your answer didn\'t match the captcha words, please try again',
- PR_MEDIUM,
- 'Recaptcha (http://recaptcha.net) provides two words in an image, and expects a user to type them in a textfield'
-);
-
-?>
View
6 tests/functional/RecatpchaFieldFunctionalTest.php
@@ -46,7 +46,7 @@ function testInvalidSubmission() {
$els = $this->cssParser()->getBySelector('#MyRecaptchaField span.validation');
// TODO Messed up newlines, no idea why...
$this->assertEquals(
- "Your answer didn't match the captcha words, please try again",
+ "Your answer didn't match the captcha words, please try again.",
str_replace(PHP_EOL, ' ', (string)$els[0])
);
}
@@ -65,10 +65,10 @@ function Form() {
$form = new Form(
$this,
'Form',
- new FieldSet(
+ new FieldList(
$f = new RecaptchaField('MyRecaptchaField')
),
- new FieldSet(
+ new FieldList(
new FormAction('doSubmit', 'submit')
)
);
View
2  tests/unit/RecatpchaFieldTest.php
@@ -6,7 +6,7 @@
class RecatpchaFieldTest extends SapphireTest {
function testValidate() {
- $form = new Form(new Controller(), 'Form', new FieldSet(), new FieldSet());
+ $form = new Form(new Controller(), 'Form', new FieldList(), new FieldList());
$f = new RecaptchaField('MyField');
$f->setHTTPClient(new RecatpchaFieldTest_HTTPClient());
$f->setForm($form);
Please sign in to comment.
Something went wrong with that request. Please try again.