PHP code example of snowsoft / laravel-recaptcha
1. Go to this page and download the library: Download snowsoft/laravel-recaptcha library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
snowsoft / laravel-recaptcha example snippets
'providers' => [
...
Biscolab\ReCaptcha\ReCaptchaServiceProvider::class,
];
'aliases' => [
...
'ReCaptcha' => Biscolab\ReCaptcha\Facades\ReCaptcha::class,
];
# in your .env file
RECAPTCHA_SITE_KEY=<YOUR_API_SITE_KEY>
RECAPTCHA_SECRET_KEY=<YOUR_API_SECRET_KEY>
RECAPTCHA_SKIP_IP=<YOUR_IP_LIST>
return [
'api_site_key' => env('RECAPTCHA_SITE_KEY', ''),
'api_secret_key' => env('RECAPTCHA_SECRET_KEY', ''),
// changed in v4.0.0
'version' => 'v2', // supported: "v3"|"v2"|"invisible"
// @since v3.4.3 changed in v4.0.0
'curl_timeout' => 10,
'skip_ip' => env('RECAPTCHA_SKIP_IP', []), // array of IP addresses - String: dotted quad format e.g.: "127.0.0.1", IP/CIDR netmask eg. 127.0.0.0/24, also 127.0.0.1 is accepted and /32 assumed
// @since v3.2.0 changed in v4.0.0
'default_validation_route' => 'biscolab-recaptcha/validate',
// @since v3.2.0 changed in v4.0.0
'default_token_parameter_name' => 'token',
// @since v3.6.0 changed in v4.0.0
'default_language' => null,
// @since v4.0.0
'default_form_id' => 'biscolab-recaptcha-invisible-form', // Only for "invisible" reCAPTCHA
// @since v4.0.0
'explicit' => false, // true|false
// @since v4.3.0
'api_domain' => "www.google.com", // default value is "www.google.com"
// @since v5.1.0
'empty_message' => false,
// @since v5.1.0
'error_message_key' => 'validation.recaptcha',
// @since v4.0.0
'tag_attributes' => [
'theme' => 'light', // "light"|"dark"
'size' => 'normal', // "normal"|"compact"
'tabindex' => 0,
'callback' => null, // DO NOT SET "biscolabOnloadCallback"
'expired-callback' => null, // DO NOT SET "biscolabOnloadCallback"
'error-callback' => null, // DO NOT SET "biscolabOnloadCallback"
]
];
return [
...
'recaptcha' => 'Hey!!! :attribute is wrong!',
];
{!! htmlFormSnippet([
"theme" => "light",
"size" => "normal",
"tabindex" => "3",
"callback" => "callbackFunction",
"expired-callback" => "expiredCallbackFunction",
"error-callback" => "errorCallbackFunction",
]) !!}
// $properties =
[
'class' => 'btn btn-info',
'data-foo' => 'bar'
]
$validator = Validator::make(request()->all(), [
...
'g-recaptcha-response' => 'recaptcha',
// OR since v4.0.0
recaptchaFieldName() => recaptchaRuleName()
]);
// check if validator fails
if($validator->fails()) {
...
$errors = $validator->errors();
}
sh
$ php artisan config:cache
blade
<form>
@csrf
...
{!! htmlFormSnippet() !!}
<!-- OR -->
{!! htmlFormSnippet($attributes) !!}
<input type="submit">
</form>
html
<!DOCTYPE html>
<html>
<head>
...
{!! htmlScriptTagJsApi([
'action' => 'homepage',
'callback_then' => 'callbackThen',
'callback_catch' => 'callbackCatch'
]) !!}
<!-- OR! -->
{!! htmlScriptTagJsApi([
'action' => 'homepage',
'custom_validation' => 'myCustomValidation'
]) !!}
</head>