Skip to content

Commit

Permalink
#221 recaptcha v3 doesn't validate in form added with elementor form …
Browse files Browse the repository at this point in the history
…builder of warehouse theme
  • Loading branch information
nenes25 committed Apr 8, 2023
1 parent 5f4da74 commit cfba2e6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
17 changes: 14 additions & 3 deletions eicaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,17 @@ public function hookHeader(array $params)
*/
protected function renderHeaderV2()
{
if (($this->context->controller instanceof AuthController && Configuration::get('CAPTCHA_ENABLE_ACCOUNT') == 1) ||
($this->context->controller instanceof ContactController && Configuration::get('CAPTCHA_ENABLE_CONTACT') == 1)
if ((
$this->context->controller instanceof AuthController
&& Configuration::get('CAPTCHA_ENABLE_ACCOUNT') == 1
)
||
(
($this->context->controller instanceof ContactController
|| Configuration::get('CAPTCHA_LOAD_EVERYWHERE') == 1
)
&& Configuration::get('CAPTCHA_ENABLE_CONTACT') == 1
)
) {
$this->context->controller->registerStylesheet(
'module-eicaptcha',
Expand Down Expand Up @@ -237,7 +246,9 @@ protected function renderHeaderV2()
public function renderHeaderV3()
{
if (
$this->context->controller instanceof ContactController
($this->context->controller instanceof ContactController
|| Configuration::get('CAPTCHA_LOAD_EVERYWHERE') == 1
)
&& Configuration::get('CAPTCHA_ENABLE_CONTACT') == 1
) {
$publicKey = Configuration::get('CAPTCHA_PUBLIC_KEY');
Expand Down
25 changes: 25 additions & 0 deletions src/ConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,29 @@ public function renderForm()
],
'tab' => 'advanced',
],
[
'type' => 'switch',
'name' => 'CAPTCHA_LOAD_EVERYWHERE',
'label' => $this->l('Load Recaptcha library everywhere'),
'hint' => $this->l('Let this option disabled by default if you don\'t use a specific contact form'),
'desc' => $this->l('Only If you use a theme with elementor or warehouse and your contact form is not on the default page, enable this option.'),
'required' => false,
'class' => 't',
'is_bool' => true,
'values' => [
[
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled'),
],
[
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled'),
],
],
'tab' => 'advanced',
],
[
'type' => 'html',
'label' => $this->l('Check module installation'),
Expand Down Expand Up @@ -339,6 +362,7 @@ public function postProcess()
Configuration::updateValue('CAPTCHA_THEME', (int) Tools::getValue('CAPTCHA_THEME'));
Configuration::updateValue('CAPTCHA_DEBUG', (int) Tools::getValue('CAPTCHA_DEBUG'));
Configuration::updateValue('CAPTCHA_USE_AUTHCONTROLLER_OVERRIDE', (int) Tools::getValue('CAPTCHA_USE_AUTHCONTROLLER_OVERRIDE'));
Configuration::updateValue('CAPTCHA_LOAD_EVERYWHERE', (int) Tools::getValue('CAPTCHA_LOAD_EVERYWHERE'));

return $this->module->displayConfirmation($this->l('Settings updated'));
}
Expand All @@ -363,6 +387,7 @@ public function getConfigFieldsValues()
'CAPTCHA_THEME' => Tools::getValue('CAPTCHA_THEME', Configuration::get('CAPTCHA_THEME')),
'CAPTCHA_DEBUG' => Tools::getValue('CAPTCHA_DEBUG', Configuration::get('CAPTCHA_DEBUG')),
'CAPTCHA_USE_AUTHCONTROLLER_OVERRIDE' => Tools::getValue('CAPTCHA_USE_AUTHCONTROLLER_OVERRIDE', Configuration::get('CAPTCHA_USE_AUTHCONTROLLER_OVERRIDE')),
'CAPTCHA_LOAD_EVERYWHERE' => Tools::getValue('CAPTCHA_LOAD_EVERYWHERE', Configuration::get('CAPTCHA_LOAD_EVERYWHERE')),
];
}

Expand Down
5 changes: 5 additions & 0 deletions upgrade/upgrade-2.5.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@
*/
function upgrade_module_2_5_0($module)
{
//Add a new configuration for websites with elementor to allow to load the recaptcha library on all pages
//But as it is unnecessary for most of the website it will be disabled by default
Configuration::updateValue('CAPTCHA_LOAD_EVERYWHERE', '0');

//For the version 8.0+ we need to use to hook as the controller has changed.
//For the version under it we let the choice to the customer, but by default we keep the legacy behavior
$enableOverride = version_compare(_PS_VERSION_, '8.0') < 0 ? '1' : '0';
Configuration::updateValue('CAPTCHA_USE_AUTHCONTROLLER_OVERRIDE', $enableOverride);

$module->uninstallOverrides();
$module->installOverrides();

Expand Down

0 comments on commit cfba2e6

Please sign in to comment.