Skip to content

Commit

Permalink
Add “Start Mode” setting to Friendly Captcha
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Sep 6, 2024
1 parent da30cb9 commit 7d17eed
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/integrations/captchas/FriendlyCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class FriendlyCaptcha extends Captcha
public ?string $secretKey = null;
public ?string $siteKey = null;
public string $language = 'en';
public string $startMode = 'none';


// Public Methods
Expand Down Expand Up @@ -74,6 +75,7 @@ public function getFrontEndJsVariables(Form $form, $page = null): ?array
'siteKey' => App::parseEnv($this->siteKey),
'formId' => $form->getFormId(),
'language' => $this->_getMatchedLanguageId() ?? 'en',
'startMode' => $this->startMode ?? 'none',
];

$src = Craft::$app->getAssetManager()->getPublishedUrl('@verbb/formie/web/assets/frontend/dist/', true, 'js/captchas/friendly-captcha.js');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,17 @@
value: integration.settings.language ?? 'auto',
options: languageOptions,
warning: macros.configWarning('language', 'formie'),
}) }}

{{ forms.selectField({
label: 'Start Mode' | t('formie'),
instructions: 'Specify when the captcha should start solving a puzzle. Refer to [docs](https://docs.friendlycaptcha.com/#/widget_api?id=data-start-attribute).' | t('formie'),
name: 'startMode',
value: integration.settings.startMode ?? 'auto',
options: [
{ label: 'Auto' | t('formie'), value: 'auto' },
{ label: 'Focus' | t('formie'), value: 'focus' },
{ label: 'None' | t('formie'), value: 'none' },
],
warning: macros.configWarning('startMode', 'formie'),
}) }}

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/web/assets/frontend/src/js/captchas/friendly-captcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class FormieFriendlyCaptcha extends FormieCaptchaProvider {
this.form = this.$form.form;
this.siteKey = settings.siteKey;
this.language = settings.language;
this.startMode = settings.startMode;

// We can have multiple captchas per form, so store them and render only when we need
this.$placeholders = this.$form.querySelectorAll('[data-friendly-captcha-placeholder]');
Expand Down Expand Up @@ -80,7 +81,7 @@ export class FormieFriendlyCaptcha extends FormieCaptchaProvider {
// Render the captcha inside the placeholder
this.widget = new WidgetInstance(this.createInput(), {
sitekey: this.siteKey,
startMode: 'none',
startMode: this.startMode,
language: this.language,
doneCallback: this.onVerify.bind(this),
errorCallback: this.onError.bind(this),
Expand Down

0 comments on commit 7d17eed

Please sign in to comment.