From 13361e745cf48b9f3ab83ffcebd1832ee7186217 Mon Sep 17 00:00:00 2001 From: Aaron Carlino Date: Thu, 9 Feb 2017 16:39:36 +1300 Subject: [PATCH] Allow instance options, language setting * The `$options` instance property was never used. Updated to merge with config. * Updated to use the proper API for setting language `/path/to/recaptcha.js?hl=language_code` --- code/RecaptchaField.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/code/RecaptchaField.php b/code/RecaptchaField.php index 52442e1..f3df094 100644 --- a/code/RecaptchaField.php +++ b/code/RecaptchaField.php @@ -113,21 +113,27 @@ public function Field($properties = array()) $previousError = Session::get("FormField.{$this->form->FormName()}.{$this->getName()}.error"); Session::clear("FormField.{$this->form->FormName()}.{$this->getName()}.error"); - $recaptchaJsUrl = self::config()->get('recaptcha_js_url'); - // js (main logic) - $jsURL = sprintf($recaptchaJsUrl, $publicKey); - if (!empty($previousError)) { - $jsURL .= "&error={$previousError}"; - } - // turn options array into data attributes $optionString = ''; - $config = self::config()->get('options') ?: array(); + $config = array_merge( + self::config()->get('options') ?: array(), + $this->options + ); + foreach ($config as $option => $value) { $optionString .= ' data-' . htmlentities($option) . '="' . htmlentities($value) . '"'; } + $jsURL = self::config()->get('recaptcha_js_url'); + if(isset($config['hl'])) { + $jsURL = HTTP::setGetVar('hl', $config['hl'], $jsURL); + } + if (!empty($previousError)) { + $jsURL = HTTP::setGetVar('error', $previousError, $jsURL); + } + Requirements::javascript($jsURL); + $fieldData = ArrayData::create( array( 'public_api_key' => self::config()->get('public_api_key'),