Commit d055473a authored by Yerzhan Hn's avatar Yerzhan Hn Committed by GitHub

Explicit rendering after an onload callback

parent cc0bacff
......@@ -9,6 +9,8 @@ class NoCaptcha
{
const CLIENT_API = 'https://www.google.com/recaptcha/api.js';
const VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify';
const ON_LOAD_CLASS = 'onloadCallBack';
const RENDER_TYPE = 'explicit';
/**
* The recaptcha secret key.
......@@ -47,14 +49,15 @@ class NoCaptcha
*
* @param array $attributes
* @param string $lang
* @param boolean $callback
*
* @return string
*/
public function display($attributes = [], $lang = null)
public function display($attributes = [], $lang = null, $callback = false, $onLoadClass = 'onloadCallBack')
{
$attributes['data-sitekey'] = $this->sitekey;
$html = '<script src="'.$this->getJsLink($lang).'" async defer></script>'."\n";
$html = '<script src="'.$this->getJsLink($lang, $callback, $onLoadClass).'" async defer></script>'."\n";
$html .= '<div class="g-recaptcha"'.$this->buildAttributes($attributes).'></div>';
return $html;
......@@ -102,12 +105,29 @@ class NoCaptcha
* Get recaptcha js link.
*
* @param string $lang
*
* @param boolean $callback
* @param string $onLoadClass
* @return string
*/
public function getJsLink($lang = null)
public function getJsLink($lang = null, $callback = false, $onLoadClass = 'onloadCallBack')
{
$client_api = static::CLIENT_API;
$params = [];
$callback ? $this->setCallBackParams($params, $onLoadClass) : false;
$lang ? $params['hl'] = $lang : null;
return $client_api . '?'. http_build_query($params);
}
/**
* @param $params
* @param $onLoadClass
*/
protected function setCallBackParams(&$params, $onLoadClass)
{
return $lang ? static::CLIENT_API.'?hl='.$lang : static::CLIENT_API;
$params['render'] = 'explicit';
$params['onload'] = $onLoadClass;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment