Skip to content

Commit

Permalink
Updating docs and other stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Mar 17, 2017
1 parent 9f1aafc commit 071fa9a
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 3 deletions.
2 changes: 0 additions & 2 deletions _docs/1-Installation-and-Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ For more details, check the [official documentation](https://developers.google.c

You can install this package via [Composer](http://getcomposer.org/) by running this command `composer require arcanedev/no-captcha`.

> For Laravel users, please check the [Version Compatibility](2-Version-Compatibility.md) section.
## Laravel

### Setup
Expand Down
40 changes: 40 additions & 0 deletions _docs/3-Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,44 @@ echo $captcha->script();

Check the [examples folder](https://github.com/ARCANEDEV/noCAPTCHA/tree/master/examples) for more usage details.

#### Invisible Captcha

The code below explains how to enable and customize the invisible reCAPTCHA on your webpage.

```php
require_once(__DIR__ . '/../vendor/autoload.php');

use Arcanedev\NoCaptcha\NoCaptcha;

$secret = 'your-secret-key';
$sitekey = 'your-site-key';
$captcha = new NoCaptcha($secret, $sitekey);

if ( ! empty($_POST)) {
$response = $_POST[NoCaptcha::CAPTCHA_NAME];
$result = $captcha->verify($response);

echo $result === true ? 'Yay ! You are a human.' : 'No ! You are a robot.';

exit();
}
?>

<form method="POST" id="demo-form">
<?php echo $captcha->button('Send', ['data-badge' => 'inline']); ?>
</form>

<?php echo $captcha->script(); ?>

<script>
function onSubmit(token) {
document.getElementById("demo-form").submit();
}
</script>
```

**NOTE :** You need to specify the invisible version in your captcha admin page. Check this page for more details: https://developers.google.com/recaptcha/docs/versions

### Laravel

#### Views
Expand Down Expand Up @@ -169,3 +207,5 @@ if ($validator->fails()) {
// Redirect back or throw an error
}
```

> For more advanced usage, check the [official recaptcha documentation](https://developers.google.com/recaptcha/intro).
13 changes: 12 additions & 1 deletion _docs/4-Extras.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
4. [Extras](4-Extras.md)
5. [FAQ](5-FAQ.md)

## g-recaptcha tag attributes
## [reCaptcha V2] g-recaptcha tag attributes

| Attributes | Value | Default | Description |
| --------------------- | ---------------- |:-------:| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
Expand All @@ -20,6 +20,17 @@
| data-callback | | | Optional. Your callback function that's executed when the user submits a successful CAPTCHA response. The user's response, `g-recaptcha-response`, will be the input for your callback function. |
| data-expired-callback | | | Optional. Your callback function that's executed when the recaptcha response expires and the user needs to solve a new CAPTCHA. |

## [Invisible reCaptcha] g-recaptcha tag attributes.

| Attributes | Value | Default | Description |
| ------------- | --------------------------------- |:-----------:| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| data-sitekey | | | Your sitekey |
| data-badge | bottomleft / inline / bottomright | bottomright | Optional. Reposition the reCAPTCHA badge. 'inline' allows you to control the CSS. |
| data-type | audio / image | image | Optional. The type of CAPTCHA to serve. |
| data-size | compact / normal | normal | Optional. The size of the widget. |
| data-tabindex | | | Optional. The tabindex of the widget and challenge. If other elements in your page use tabindex, it should be set to make user navigation easier. |
| data-callback | | onSubmit | Optional. Your callback function that's executed when the user submits a successful CAPTCHA response. The user's response, `g-recaptcha-response`, will be the input for your callback function. |

## Examples

Check the [examples folder](https://github.com/ARCANEDEV/noCAPTCHA/tree/master/examples) for more usage details.
31 changes: 31 additions & 0 deletions examples/invisible-captcha.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

require_once(__DIR__ . '/../vendor/autoload.php');

use Arcanedev\NoCaptcha\NoCaptcha;

$secret = 'your-secret-key';
$sitekey = 'your-site-key';
$captcha = new NoCaptcha($secret, $sitekey);

if ( ! empty($_POST)) {
$response = $_POST[NoCaptcha::CAPTCHA_NAME];
$result = $captcha->verify($response);

echo $result === true ? 'Yay ! You are a human.' : 'No ! You are a robot.';

exit();
}
?>

<form method="POST" id="demo-form">
<?php echo $captcha->button('Send'); ?>
</form>

<?php echo $captcha->script(); ?>

<script>
function onSubmit(token) {
document.getElementById("demo-form").submit();
}
</script>
5 changes: 5 additions & 0 deletions tests/NoCaptchaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ public function it_can_display_invisible_captcha()
$this->noCaptcha->button('Send')
);

$this->assertSame(
'<button class="g-recaptcha" data-sitekey="site-key" data-callback="submitForm">Post the form</button>',
$this->noCaptcha->button('Post the form', ['data-callback' => 'submitForm'])
);

$this->assertSame(
'<button class="g-recaptcha" data-sitekey="site-key" data-callback="onSubmit" data-size="invisible">Send</button>',
$this->noCaptcha->button('Send', ['data-size' => 'invisible'])
Expand Down

0 comments on commit 071fa9a

Please sign in to comment.