Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
no-captcha
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
CENTER-TBI
no-captcha
Commits
1bafc19a
Commit
1bafc19a
authored
Oct 05, 2017
by
Nguyen Van Anh
Committed by
GitHub
Oct 05, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #86 from dosarkz/master
Explicit rendering after an onload callback
parents
bc936d1a
30599897
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
10 deletions
+43
-10
README.md
README.md
+7
-1
src/NoCaptcha.php
src/NoCaptcha.php
+36
-9
No files found.
README.md
View file @
1bafc19a
...
...
@@ -32,6 +32,12 @@ NOCAPTCHA_SITEKEY=site-key
### Usage
##### Init js source
```
{!! app('captcha')->renderJs($lang = 'en', $callback = false, $onLoadClass = 'recaptchaCallback') !!}
```
##### Display reCAPTCHA
```
php
...
...
@@ -41,7 +47,7 @@ NOCAPTCHA_SITEKEY=site-key
With custom attributes and language support:
```
{!! app('captcha')->display($attributes = []
, $lang = null
); !!}
{!! app('captcha')->display($attributes = []); !!}
```
##### Validation
...
...
src/NoCaptcha.php
View file @
1bafc19a
...
...
@@ -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,18 +49,26 @@ class NoCaptcha
* Render HTML captcha.
*
* @param array $attributes
* @param string $lang
*
* @return string
*/
public
function
display
(
$attributes
=
[]
,
$lang
=
null
)
public
function
display
(
$attributes
=
[])
{
$attributes
[
'data-sitekey'
]
=
$this
->
sitekey
;
return
'<div class="g-recaptcha"'
.
$this
->
buildAttributes
(
$attributes
)
.
'></div>'
;
}
$html
=
'<script src="'
.
$this
->
getJsLink
(
$lang
)
.
'" async defer></script>'
.
"
\n
"
;
$html
.=
'<div class="g-recaptcha"'
.
$this
->
buildAttributes
(
$attributes
)
.
'></div>'
;
return
$html
;
/**
* Render js source
*
* @param null $lang
* @param bool $callback
* @param string $onLoadClass
* @return string
*/
public
function
renderJs
(
$lang
=
null
,
$callback
=
false
,
$onLoadClass
=
'onloadCallBack'
)
{
return
'<script src="'
.
$this
->
getJsLink
(
$lang
,
$callback
,
$onLoadClass
)
.
'" async defer></script>'
.
"
\n
"
;
}
/**
...
...
@@ -103,12 +113,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
;
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment