Skip to content

Commit

Permalink
Merge pull request #32 from jacksleight/additional-tag-params
Browse files Browse the repository at this point in the history
Support passing additional tag parameters to captcha element
  • Loading branch information
aryehraber authored Nov 27, 2021
2 parents 7d87a0e + f3959ff commit 2e7046b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace AryehRaber\Captcha;

use GuzzleHttp\Client;
use Illuminate\Support\Collection;
use Illuminate\Validation\ValidationException;

abstract class Captcha
Expand All @@ -22,7 +23,7 @@ abstract public function getVerificationUrl();

abstract public function getDefaultDisclaimer();

abstract public function renderIndexTag();
abstract public function renderIndexTag(Collection $params);

abstract public function renderHeadTag();

Expand Down
2 changes: 1 addition & 1 deletion src/CaptchaTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(Captcha $captcha)
*/
public function index()
{
return $this->captcha->renderIndexTag();
return $this->captcha->renderIndexTag($this->params);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Hcaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace AryehRaber\Captcha;

use Illuminate\Support\Collection;

class Hcaptcha extends Captcha
{
public function getResponseToken()
Expand All @@ -19,12 +21,12 @@ public function getDefaultDisclaimer()
return 'This site is protected by hCaptcha and its <a href="https://hcaptcha.com/privacy">Privacy Policy</a> and <a href="https://hcaptcha.com/terms">Terms of Service</a> apply.';
}

public function renderIndexTag()
public function renderIndexTag(Collection $params)
{
$attributes = $this->buildAttributes([
$attributes = $this->buildAttributes($params->merge([
'data-sitekey' => $this->getSiteKey(),
'data-size' => config('captcha.invisible') ? 'invisible' : '',
]);
]));

return "<div class=\"h-captcha\" {$attributes}></div>";
}
Expand Down
8 changes: 5 additions & 3 deletions src/Recaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace AryehRaber\Captcha;

use Illuminate\Support\Collection;

class Recaptcha extends Captcha
{
public function getResponseToken()
Expand All @@ -19,12 +21,12 @@ public function getDefaultDisclaimer()
return 'This site is protected by reCAPTCHA and the Google [Privacy Policy](https://policies.google.com/privacy) and [Terms of Service](https://policies.google.com/terms) apply.';
}

public function renderIndexTag()
public function renderIndexTag(Collection $params)
{
$attributes = $this->buildAttributes([
$attributes = $this->buildAttributes($params->merge([
'data-sitekey' => $this->getSiteKey(),
'data-size' => config('captcha.invisible') ? 'invisible' : '',
]);
]));

return "<div class=\"g-recaptcha\" {$attributes}></div>";
}
Expand Down

0 comments on commit 2e7046b

Please sign in to comment.