123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- namespace Ppb\Form\Element;
- use Cube\Form\Element,
- Cube\Controller\Front,
- Ppb\Validate;
- class ReCaptcha extends Element
- {
-
- protected $_element = 'ReCaptcha';
-
- public static $loaded = false;
-
- public function __construct($name)
- {
- parent::__construct($this->_element, $name);
- self::$loaded = true;
- $this->addValidator(
- new Validate\ReCaptcha()
- );
- }
-
- public function render()
- {
- $settings = Front::getInstance()->getBootstrap()->getResource('settings');
- $customData[] = "'sitekey' : '" . $settings['recaptcha_public_key'] . "'";
- foreach ((array)$this->_customData as $key => $value) {
- $customData[] = "'{$key}' : '{$value}'";
- }
- $callbackFunctionName = 'onloadCallback' . ucfirst($this->_name);
- return '
- <script type="text/javascript">
- var onloadCallback = function() {
- grecaptcha.render("' . $this->_name . '", {
- ' . implode(', ', $customData) . '
- });
- };
- </script>
- <div id="' . $this->_name . '"></div>
- <script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
- async defer></script>';
- }
- }
|