You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't understand the behaviour or intention of returning null here (albeit this was the Craft 3 way I suppose).
If I e.g. use this to try and verify a user registration form, then if the recaptcha fails, I get a 404 not found response, which is...odd.
In an ajax scenario this is awkward (at best) to handle, and the flash message of Unable to verify your submission is not accessible via javascript (I believe?).
$error = "Unable to verify your submission";
return $this->asFailure($error, [], ['message' => $error]);`
That will return the correct 400 status code, set a message in the routeParams and a message in the repsonseJSON so that in your error handler you can then e.g.
// Handle errors coming back from Craft
if (request.status === 400){
console.log(request.responseJSON);
}
Would you accept a PR for this change? It will obviously change the behaviour, but would be changing it to the proper Craft 4 way (as I understand it!)
The text was updated successfully, but these errors were encountered:
https://github.com/matt-west/craft-recaptcha/blob/d95e16a559899dca16afd50ecb88452569ecf216/src/controllers/RecaptchaController.php#LL40C4-L40C16
I don't understand the behaviour or intention of returning null here (albeit this was the Craft 3 way I suppose).
If I e.g. use this to try and verify a user registration form, then if the recaptcha fails, I get a 404 not found response, which is...odd.
In an ajax scenario this is awkward (at best) to handle, and the flash message of
Unable to verify your submission
is not accessible via javascript (I believe?).Controllers in Craft 4 should be using the new
asSuccess
andasFailure
returns, with an optional message. See:https://craftcms.com/docs/4.x/extend/updating-plugins.html#controller-responses
So really this should be something like:
That will return the correct 400 status code, set a message in the
routeParams
and amessage
in therepsonseJSON
so that in your error handler you can then e.g.Would you accept a PR for this change? It will obviously change the behaviour, but would be changing it to the proper Craft 4 way (as I understand it!)
The text was updated successfully, but these errors were encountered: