From 32afb9ce64662c4d6a0a74ac8a3de25d14117fe6 Mon Sep 17 00:00:00 2001 From: Brandon Shipley Date: Sat, 14 Nov 2026 16:56:35 -0800 Subject: [PATCH 1/6] split config for turnstile + turnstile helper updates --- config/app.example.php | 18 ++++------ .../Component/ContactUsComponent.php | 12 +++---- src/View/Helper/TurnstileHelper.php | 33 +++++++++++++++++-- templates/ContactUsFormSubmissions/add.php | 2 +- .../element/ContactUsFormSubmissions/form.php | 1 + ...ContactUsFormSubmissionsControllerTest.php | 11 +++++-- tests/bootstrap.php | 5 ++- 7 files changed, 58 insertions(+), 24 deletions(-) diff --git a/config/app.example.php b/config/app.example.php index 4a65788..ff74c32 100644 --- a/config/app.example.php +++ b/config/app.example.php @@ -7,6 +7,7 @@ return [ 'subject' => true, 'email' => true, 'captcha' => true, + 'turnstile' => true, ], 'clientIpHeader' => null, 'email' => [ @@ -26,18 +27,13 @@ return [ 'controller' => 'ContactUsFormSubmissions', 'action' => 'view', ], + ], + 'Turnstile' => [ + 'enabled' => true, /** - * @link https://developers.cloudflare.com/turnstile/troubleshooting/testing/ - * - * secretKeys for testing: - * always passes = 1x0000000000000000000000000000000AA - * always fails = 2x0000000000000000000000000000000AA - * token already spent error 3x0000000000000000000000000000000AA + * @link https://developers.cloudflare.com/turnstile/troubleshooting/testing/ for testing keys */ - 'turnstile' => [ - 'enabled' => true, - 'siteKey' => '{SITE_KEY_GOES_HERE}', // define in app_local or an .env variable - CLOUDFLARE_TURNSTILE_SITE_KEY - 'secretKey' => '{SECRET_GOES_HERE}', // define in app_local or an .env variable - CLOUDFLARE_TURNSTILE_SECRET_KEY - ], + 'siteKey' => '{SITE_KEY_GOES_HERE}', // define in app_local or an .env variable - CLOUDFLARE_TURNSTILE_SITE_KEY + 'secretKey' => '{SECRET_GOES_HERE}', // define in app_local or an .env variable - CLOUDFLARE_TURNSTILE_SECRET_KEY ], ]; diff --git a/src/Controller/Component/ContactUsComponent.php b/src/Controller/Component/ContactUsComponent.php index 0f18403..ba5599a 100644 --- a/src/Controller/Component/ContactUsComponent.php +++ b/src/Controller/Component/ContactUsComponent.php @@ -81,19 +81,17 @@ class ContactUsComponent extends Component { $this->ContactUsFormSubmissions = TableRegistry::getTableLocator()->get('CakeContactUs.ContactUsFormSubmissions'); $requireCaptcha = Configure::readOrFail('ContactUs.fields.captcha'); - $useTurnstile = Configure::read('ContactUs.turnstile', [ - 'enabled' => false, - ]); + $requireTurnstile = Configure::readOrFail('ContactUs.fields.turnstile'); $this->setConfig('redirectUrl', Configure::read('ContactUs.redirectUrl', '/')); $this->setConfig('addIdToRedirect', Configure::read('ContactUs.addIdToRedirect', false)); $this->setConfig('requireEmail', Configure::readOrFail('ContactUs.fields.email')); $this->setConfig('requireCaptcha', $requireCaptcha); - $this->setConfig('turnstile', $useTurnstile); if ($requireCaptcha) { $this->getController()->viewBuilder()->addHelpers(['Captcha.Captcha']); } - if ($useTurnstile['enabled'] ?? false) { -// $this->getController()->viewBuilder()->addHelpers(['Turnstile']); + if ($requireTurnstile) { + $this->setConfig('turnstile', Configure::readOrFail('Turnstile')); + $this->getController()->viewBuilder()->addHelper('CakeContactUs.Turnstile', Configure::readOrFail('Turnstile')); } } @@ -126,6 +124,8 @@ class ContactUsComponent extends Component { 'contactUsFormSubmission' => $contactUsFormSubmission, ], $this->getController()); $result = $event->getResult(); + + // only thing within this plugin that will stop processing here is if turnstile validation fails if ($event->isStopped()) { if ($result['redirect'] ?? false) { return $this->getController()->redirect($result['redirect']); diff --git a/src/View/Helper/TurnstileHelper.php b/src/View/Helper/TurnstileHelper.php index 2cb2aed..64493e8 100644 --- a/src/View/Helper/TurnstileHelper.php +++ b/src/View/Helper/TurnstileHelper.php @@ -19,7 +19,9 @@ class TurnstileHelper extends Helper { * * @var array */ - protected array $_defaultConfig = []; + protected array $_defaultConfig = [ + 'eventListeners' => true, + ]; /** * @var array|string[] @@ -31,7 +33,7 @@ class TurnstileHelper extends Helper { * @param array $config */ public function __construct(View $view, array $config = []) { - $config += (array)Configure::read('ContactUs.turnstile'); + $config += (array)Configure::read('Turnstile'); parent::__construct($view, $config); } @@ -46,6 +48,31 @@ class TurnstileHelper extends Helper { /** * @param array $options * + * @return string + */ + public function render(array $options = []) { + $options += [ + 'class' => 'cf-turnstile', + 'data-sitekey' => $this->getConfigOrFail('siteKey'), + 'data-theme' => 'auto', + 'data-size' => 'flexible', + 'eventListeners' => $this->getConfig('eventListeners'), + ]; + if ($options['eventListeners']) { + $options += [ + 'data-callback' => 'onTurnstileSuccess', + 'data-error-callback' => 'onTurnstileError', + 'data-expired-callback' => 'onTurnstileExpired', + ]; + } + unset($options['eventListeners']); + + return $this->Html->div($options['class'], '', $options); + } + + /** + * @param array $options + * * @return string|null */ public function script(array $options = []) { @@ -80,7 +107,7 @@ class TurnstileHelper extends Helper { $final .= $this->onTurnstileExpired($options); $final .= ''; - return $final; + return $this->Html->scriptBlock($final); } /** diff --git a/templates/ContactUsFormSubmissions/add.php b/templates/ContactUsFormSubmissions/add.php index 17e8219..689931e 100644 --- a/templates/ContactUsFormSubmissions/add.php +++ b/templates/ContactUsFormSubmissions/add.php @@ -12,7 +12,7 @@ element('ContactUsFormSubmissions/form'); ?> - Form->button(__('Submit')) ?> + Form->button(__('Submit'), ['id' => 'submit-btn']) ?> Form->end() ?> diff --git a/templates/element/ContactUsFormSubmissions/form.php b/templates/element/ContactUsFormSubmissions/form.php index 22c779f..5533f15 100644 --- a/templates/element/ContactUsFormSubmissions/form.php +++ b/templates/element/ContactUsFormSubmissions/form.php @@ -13,4 +13,5 @@ echo isset($fields['email']) && $fields['email'] ? $this->Form->control('email', echo isset($fields['subject']) && $fields['subject'] ? $this->Form->control('subject', ['required' => true]) : ''; echo $this->Form->control('message'); echo isset($fields['captcha']) && $fields['captcha'] ? $this->Captcha->render(['placeholder' => __('Please solve the riddle')]) : ''; +echo isset($fields['turnstile']) && $fields['turnstile'] ? $this->Turnstile->render() : ''; ?> diff --git a/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php b/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php index 02fa224..ec503c2 100644 --- a/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php +++ b/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php @@ -125,7 +125,9 @@ class ContactUsFormSubmissionsControllerTest extends TestCase { */ public function testAddPostSuccessWithTurnstile(): void { $cntBefore = $this->ContactUsFormSubmissions->find()->count(); - Configure::write('ContactUs.turnstile', [ + Configure::write('ContactUs.fields.turnstile', true); + Configure::write('Turnstile', [ + 'enabled' => true, 'siteKey' => '1x00000000000000000000AA', 'secretKey' => '1x0000000000000000000000000000000AA', ]); @@ -161,7 +163,9 @@ class ContactUsFormSubmissionsControllerTest extends TestCase { */ public function testAddPostInvalidTurnstile(): void { $cntBefore = $this->ContactUsFormSubmissions->find()->count(); - Configure::write('ContactUs.turnstile', [ + Configure::write('ContactUs.fields.turnstile', true); + Configure::write('Turnstile', [ + 'enabled' => true, 'siteKey' => '2x00000000000000000000BB', 'secretKey' => '2x0000000000000000000000000000000AA', ]); @@ -178,6 +182,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase { 'cf-turnstile-response' => 'XXXX.DUMMY.TOKEN.XXXX', ]; $this->post($url, $data); +// dd($this->_response); $this->assertResponseCode(200); $cntAfter = $this->ContactUsFormSubmissions->find()->count(); $this->assertEquals($cntBefore, $cntAfter); @@ -198,6 +203,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase { Configure::write('ContactUs.fields', [ 'captcha' => false, 'email' => true, + 'turnstile' => false, ]); Configure::write('ContactUs.email', [ 'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions', @@ -244,6 +250,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase { Configure::write('ContactUs.fields', [ 'captcha' => false, 'email' => true, + 'turnstile' => false, ]); Configure::write('ContactUs.email', [ 'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions', diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4414081..826599a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -63,6 +63,7 @@ Configure::write('ContactUs', [ 'fields' => [ 'captcha' => false, 'email' => true, + 'turnstile' => false, ], 'email' => [ 'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions', @@ -72,12 +73,14 @@ Configure::write('ContactUs', [ 'to' => 'test@example.com', ], ], - 'turnstile' => false, // 'turnstile' => [ // 'siteKey' => '1x00000000000000000000AA', // 'secretKey' => '1x0000000000000000000000000000000AA', // ], ]); +Configure::write('Turnstile', [ + 'enabled' => false, +]); Configure::write('EmailTransport', [ 'default' => [ 'className' => DebugTransport::class, From 35fab648f7f29649f86bc063e75836508912b8da Mon Sep 17 00:00:00 2001 From: Brandon Shipley Date: Sat, 14 Nov 2026 18:38:09 -0800 Subject: [PATCH 2/6] back and forth on config - if should come from configure or from component config - stupid lol unit testing different tokens for turnstile lends to keeping that out of component config --- config/app.example.php | 7 +-- .../Component/ContactUsComponent.php | 49 ++++++++++--------- .../ContactUsFormSubmissionsController.php | 4 +- ...ContactUsFormSubmissionsControllerTest.php | 1 - tests/bootstrap.php | 4 ++ 5 files changed, 37 insertions(+), 28 deletions(-) diff --git a/config/app.example.php b/config/app.example.php index ff74c32..7981311 100644 --- a/config/app.example.php +++ b/config/app.example.php @@ -4,10 +4,10 @@ return [ 'ContactUs' => [ 'fields' => [ - 'subject' => true, + 'subject' => false, 'email' => true, - 'captcha' => true, - 'turnstile' => true, + 'captcha' => false, + 'turnstile' => false, ], 'clientIpHeader' => null, 'email' => [ @@ -20,6 +20,7 @@ return [ 'bcc' => '', // email string or array of emails ], ], + 'model' => 'CakeContactUs.ContactUsFormSubmissions', 'addIdToRedirect' => true, 'redirectUrl' => [ 'prefix' => 'Admin', diff --git a/src/Controller/Component/ContactUsComponent.php b/src/Controller/Component/ContactUsComponent.php index ba5599a..4a9ef3b 100644 --- a/src/Controller/Component/ContactUsComponent.php +++ b/src/Controller/Component/ContactUsComponent.php @@ -24,14 +24,17 @@ class ContactUsComponent extends Component { /** * @var \CakeContactUs\Model\Table\ContactUsFormSubmissionsTable|\Cake\ORM\Table */ - protected ContactUsFormSubmissionsTable|Table $ContactUsFormSubmissions; + protected ContactUsFormSubmissionsTable|Table $table; /** * Default configuration. * * @var array */ - protected array $_defaultConfig = []; + protected array $_defaultConfig = [ + 'actions' => [], + 'model' => 'CakeContactUs.ContactUsFormSubmissions', + ]; /** * @var array|string[] @@ -76,21 +79,22 @@ class ContactUsComponent extends Component { * */ public function initialize(array $config): void { + $config = array_merge($config, Configure::read('ContactUs')); + $this->setConfig($config); parent::initialize($config); // TODO: Change the autogenerated stub + $this->table = TableRegistry::getTableLocator()->get($this->getConfig('model')); + } - $this->ContactUsFormSubmissions = TableRegistry::getTableLocator()->get('CakeContactUs.ContactUsFormSubmissions'); - - $requireCaptcha = Configure::readOrFail('ContactUs.fields.captcha'); - $requireTurnstile = Configure::readOrFail('ContactUs.fields.turnstile'); - $this->setConfig('redirectUrl', Configure::read('ContactUs.redirectUrl', '/')); - $this->setConfig('addIdToRedirect', Configure::read('ContactUs.addIdToRedirect', false)); - $this->setConfig('requireEmail', Configure::readOrFail('ContactUs.fields.email')); - $this->setConfig('requireCaptcha', $requireCaptcha); - if ($requireCaptcha) { + /** + * @param \Cake\Event\EventInterface $event + * + * @return void + */ + public function beforeRender(EventInterface $event): void { + if (Configure::read('ContactUs.fields.captcha')) { $this->getController()->viewBuilder()->addHelpers(['Captcha.Captcha']); } - if ($requireTurnstile) { - $this->setConfig('turnstile', Configure::readOrFail('Turnstile')); + if (Configure::read('ContactUs.fields.turnstile')) { $this->getController()->viewBuilder()->addHelper('CakeContactUs.Turnstile', Configure::readOrFail('Turnstile')); } } @@ -100,10 +104,10 @@ class ContactUsComponent extends Component { */ public function newContactUsForm() { if ($this->getConfig('requireCaptcha') && PHP_SAPI !== 'cli') { - $this->ContactUsFormSubmissions->addBehavior('Captcha.Captcha'); + $this->table->addBehavior('Captcha.Captcha'); } - return $this->ContactUsFormSubmissions->newEmptyEntity(); + return $this->table->newEmptyEntity(); } /** @@ -117,7 +121,7 @@ class ContactUsComponent extends Component { } $postData['client_ip'] = $this->_getIp(); $postData['submitted_at'] = DateTime::now(); - $contactUsFormSubmission = $this->ContactUsFormSubmissions->patchEntity($contactUsFormSubmission, $postData); + $contactUsFormSubmission = $this->table->patchEntity($contactUsFormSubmission, $postData); $this->getController()->set(['contactUsFormSubmission' => $contactUsFormSubmission]); $event = $this->getController()->dispatchEvent(CakeContactUsPlugin::EVENT_BEFORE_CONTACT_US_FORM_SAVED, [ @@ -180,10 +184,9 @@ class ContactUsComponent extends Component { return $result; } $this->Flash->success($message); - $redirectUrl = $this->getConfig('redirectUrl'); if ($this->getConfig('addIdToRedirect')) { - $redirectUrl[] = $contactUsFormSubmissionSaved->get($this->ContactUsFormSubmissions->getPrimaryKey()); + $redirectUrl[] = $contactUsFormSubmissionSaved->get($this->table->getPrimaryKey()); } return $this->getController()->redirect($redirectUrl); @@ -193,11 +196,11 @@ class ContactUsComponent extends Component { * @return void */ public function beforeFormSaved(EventInterface $event) { - if (!$this->getConfig('turnstile')) { + if (!Configure::read('ContactUs.fields.turnstile')) { return; } - $siteKey = getenv(CakeContactUsPlugin::CAKE_CONTACT_US_CLOUDFLARE_TURNSTILE_SITE_KEY) ?: $this->getConfig('turnstile.siteKey'); - $secretKey = getenv(CakeContactUsPlugin::CAKE_CONTACT_US_CLOUDFLARE_TURNSTILE_SECRET_KEY) ?: $this->getConfig('turnstile.secretKey'); + $siteKey = getenv(CakeContactUsPlugin::CAKE_CONTACT_US_CLOUDFLARE_TURNSTILE_SITE_KEY) ?: Configure::readOrFail('Turnstile.siteKey'); + $secretKey = getenv(CakeContactUsPlugin::CAKE_CONTACT_US_CLOUDFLARE_TURNSTILE_SECRET_KEY) ?: Configure::readOrFail('Turnstile.secretKey'); if (!$siteKey || !$secretKey) { $event->stopPropagation(); $event->setResult([ @@ -247,7 +250,7 @@ class ContactUsComponent extends Component { * @return \Cake\Datasource\EntityInterface|\Cake\Http\Response */ protected function _finishSave(EntityInterface $contactUsFormSubmission) { - $contactUsFormSubmissionSaved = $this->ContactUsFormSubmissions->save($contactUsFormSubmission); + $contactUsFormSubmissionSaved = $this->table->save($contactUsFormSubmission); if ($contactUsFormSubmissionSaved) { return $this->_afterFormSaved($contactUsFormSubmissionSaved); @@ -268,7 +271,7 @@ class ContactUsComponent extends Component { // } $url = 'https://challenges.cloudflare.com/turnstile/v0/siteverify'; $data = [ - 'secret' => $this->getConfig('turnstile.secretKey'), + 'secret' => Configure::readOrFail('Turnstile.secretKey'), 'response' => $token, ]; diff --git a/src/Controller/ContactUsFormSubmissionsController.php b/src/Controller/ContactUsFormSubmissionsController.php index fa78b4a..6033bd2 100644 --- a/src/Controller/ContactUsFormSubmissionsController.php +++ b/src/Controller/ContactUsFormSubmissionsController.php @@ -18,7 +18,9 @@ class ContactUsFormSubmissionsController extends AppController { */ public function initialize(): void { parent::initialize(); // TODO: Change the autogenerated stub - $this->loadComponent('CakeContactUs.ContactUs'); + $this->loadComponent('CakeContactUs.ContactUs', [ + 'actions' => ['contact'], + ]); } /** diff --git a/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php b/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php index ec503c2..cf39664 100644 --- a/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php +++ b/tests/TestCase/Controller/ContactUsFormSubmissionsControllerTest.php @@ -182,7 +182,6 @@ class ContactUsFormSubmissionsControllerTest extends TestCase { 'cf-turnstile-response' => 'XXXX.DUMMY.TOKEN.XXXX', ]; $this->post($url, $data); -// dd($this->_response); $this->assertResponseCode(200); $cntAfter = $this->ContactUsFormSubmissions->find()->count(); $this->assertEquals($cntBefore, $cntAfter); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 826599a..be5f1f1 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -65,6 +65,9 @@ Configure::write('ContactUs', [ 'email' => true, 'turnstile' => false, ], + 'model' => 'CakeContactUs.ContactUsFormSubmissions', + 'addIdToRedirect' => false, + 'redirectUrl' => '/', 'email' => [ 'mailerClass' => 'CakeContactUs.ContactUsFormSubmissions', 'confirmation' => false, // true or false @@ -73,6 +76,7 @@ Configure::write('ContactUs', [ 'to' => 'test@example.com', ], ], + // 'turnstile' => [ // 'siteKey' => '1x00000000000000000000AA', // 'secretKey' => '1x0000000000000000000000000000000AA', From 0cc1894445ea27a3831e3bb895e44ad7ae526065 Mon Sep 17 00:00:00 2001 From: Brandon Shipley Date: Sat, 14 Nov 2026 18:54:34 -0800 Subject: [PATCH 3/6] handle form protection component being loaded - unlock cf turnstile field --- src/Controller/Component/ContactUsComponent.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Controller/Component/ContactUsComponent.php b/src/Controller/Component/ContactUsComponent.php index 4a9ef3b..8d62b74 100644 --- a/src/Controller/Component/ContactUsComponent.php +++ b/src/Controller/Component/ContactUsComponent.php @@ -83,6 +83,10 @@ class ContactUsComponent extends Component { $this->setConfig($config); parent::initialize($config); // TODO: Change the autogenerated stub $this->table = TableRegistry::getTableLocator()->get($this->getConfig('model')); + if (Configure::read('ContactUs.fields.turnstile') && $this->getController()->components()->has('FormProtection')) { + $this->getController()->components()->get('FormProtection') + ->unlockFields('cf-turnstile-response'); + } } /** From 71f571f16b18e27eb7372a844bc6a8bbcfa4a040 Mon Sep 17 00:00:00 2001 From: Brandon Shipley Date: Sat, 14 Nov 2026 23:57:01 -0800 Subject: [PATCH 4/6] phpstan fix check if method exists first --- src/Controller/Component/ContactUsComponent.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Controller/Component/ContactUsComponent.php b/src/Controller/Component/ContactUsComponent.php index 8d62b74..188619e 100644 --- a/src/Controller/Component/ContactUsComponent.php +++ b/src/Controller/Component/ContactUsComponent.php @@ -83,7 +83,10 @@ class ContactUsComponent extends Component { $this->setConfig($config); parent::initialize($config); // TODO: Change the autogenerated stub $this->table = TableRegistry::getTableLocator()->get($this->getConfig('model')); - if (Configure::read('ContactUs.fields.turnstile') && $this->getController()->components()->has('FormProtection')) { + if (Configure::read('ContactUs.fields.turnstile') && + $this->getController()->components()->has('FormProtection') && + method_exists($this->getController()->components()->get('FormProtection'), 'unlockFields') + ) { $this->getController()->components()->get('FormProtection') ->unlockFields('cf-turnstile-response'); } From 1446a80811ee7aa783cad67a2fd3cab3b976d9fa Mon Sep 17 00:00:00 2001 From: Brandon Shipley Date: Sun, 15 Nov 2026 00:49:44 -0800 Subject: [PATCH 5/6] code style fix componentg --- src/Controller/Component/ContactUsComponent.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Controller/Component/ContactUsComponent.php b/src/Controller/Component/ContactUsComponent.php index 188619e..87fbcce 100644 --- a/src/Controller/Component/ContactUsComponent.php +++ b/src/Controller/Component/ContactUsComponent.php @@ -83,13 +83,13 @@ class ContactUsComponent extends Component { $this->setConfig($config); parent::initialize($config); // TODO: Change the autogenerated stub $this->table = TableRegistry::getTableLocator()->get($this->getConfig('model')); - if (Configure::read('ContactUs.fields.turnstile') && - $this->getController()->components()->has('FormProtection') && - method_exists($this->getController()->components()->get('FormProtection'), 'unlockFields') - ) { - $this->getController()->components()->get('FormProtection') - ->unlockFields('cf-turnstile-response'); - } + if (Configure::read('ContactUs.fields.turnstile') && + $this->getController()->components()->has('FormProtection') && + method_exists($this->getController()->components()->get('FormProtection'), 'unlockFields') + ) { + $this->getController()->components()->get('FormProtection') + ->unlockFields('cf-turnstile-response'); + } } /** From 27196c95d076e528bd4ce282eb2a2ea1aa38fdcb Mon Sep 17 00:00:00 2001 From: Brandon Shipley Date: Sun, 15 Nov 2026 01:41:15 -0800 Subject: [PATCH 6/6] csc --- src/Controller/Component/ContactUsComponent.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Controller/Component/ContactUsComponent.php b/src/Controller/Component/ContactUsComponent.php index 87fbcce..1a30574 100644 --- a/src/Controller/Component/ContactUsComponent.php +++ b/src/Controller/Component/ContactUsComponent.php @@ -83,12 +83,14 @@ class ContactUsComponent extends Component { $this->setConfig($config); parent::initialize($config); // TODO: Change the autogenerated stub $this->table = TableRegistry::getTableLocator()->get($this->getConfig('model')); - if (Configure::read('ContactUs.fields.turnstile') && - $this->getController()->components()->has('FormProtection') && - method_exists($this->getController()->components()->get('FormProtection'), 'unlockFields') - ) { - $this->getController()->components()->get('FormProtection') - ->unlockFields('cf-turnstile-response'); + if (!Configure::read('ContactUs.fields.turnstile')) { + return; + } + if (!$this->getController()->components()->has('FormProtection')) { + return; + } + if (method_exists($this->getController()->components()->get('FormProtection'), 'unlockFields')) { + $this->getController()->components()->get('FormProtection')->unlockFields('cf-turnstile-response'); } }