From 4896e22a6ab539ce692b74f07be986bc2c71de95 Mon Sep 17 00:00:00 2001 From: bossanova808 Date: Tue, 23 May 2023 13:36:39 +1000 Subject: [PATCH] Add proper Craft 4 controller return for easier handling with ajax requests --- src/controllers/RecaptchaController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/controllers/RecaptchaController.php b/src/controllers/RecaptchaController.php index ca62fd7..c4b0dc8 100644 --- a/src/controllers/RecaptchaController.php +++ b/src/controllers/RecaptchaController.php @@ -35,9 +35,10 @@ public function actionVerifySubmission() // if it's verified, then pass it on to the intended action, otherwise set a session error and return null if ($verified) { return Controller::run('/' . $action, func_get_args()); // run the intended action (add / to force it's scope to be outside the plugin) with all the params passed to this controller action - } else { - Craft::$app->getSession()->setError(Craft::t('site', 'Unable to verify your submission.')); - return null; } + + $error = 'Unable to verify your submission.'; + Craft::$app->getSession()->setError(Craft::t('site', $error)); + return $this->asFailure($error, [], ['message' => $error]); } }