Back to Captcha Support

jerry3850
jerry3850

I am submitting my form using AJAX and trying to listen for the ajaxErrorMessage event as shown below:

<script>
    $(window).on('ajaxErrorMessage', function(event, message) {
        $('#errors').html(message);
        event.preventDefault();
    })
</script>
<div id="errors"></div>

I placed the above code above my form tag, but when I submit my form without checking the recaptcha, the form is submitted without showing an error. What am I doing wrong?

alxy
alxy

Hi, are you absolutely sure the form ist successfully beeing processed? Please check the network tab in your browser to see the actual result of the form submit. It should be a 406 resut code.

I will definetly look into this later (tonight), and see if I get the same result.

jerry3850
jerry3850

Thanks for your reply alxy. I checked the network tab and it shows a 200 OK HTTP status code. As you point out, since I left the captcha unchecked it should have responded with a 406 code so I can listen for the ajaxErrorMessage event to customize the error behavior -- but this error code was not sent.

rumych9431
rumych9431

Hi. I am trying to use your plugin on my site. when the form is submitted using AJAX. filling out the captcha and submit the form with an empty required field first get the response that the field is empty, but when re-submitting a form get an error sending Ajax Exception in Captcha Middleware.php line 37: [] . tell please, after sending the completed forms, captcha should be updated and why I get this error? thanks.

Last updated

alxy
alxy

Hi,

can you please provide more information about the error you are getting. It is absolutely correct that the plugin throws an exception if the captcha is not solved correctly, see https://github.com/alxy/oc-captcha-plugin/blob/master/middleware/CaptchaMiddleware.php#L37

You are responsible of handling this exception.

OR, do you think the issue is, that the CAPTCHA needs to be updated after one unsuccessful request? I can imagine it never validates after one wrong submit of the form - is this the case?

vlad123
vlad123

I have the same problem as rumych9431.

OR, do you think the issue is, that the CAPTCHA needs to be updated after one unsuccessful request? I can imagine it never validates after one wrong submit of the form - is this the

This seems to be the case. However I don't see any possibility to restart the CAPTCHA. It remains checked all the time despite CaptchaMiddleware throwing the AjaxException.

alxy
alxy

Hi, thanks for the feedback. Could you further debug this? Im unsure how we could solve this issue in a good way.

If you have any idea, let me know :)

penna20166
penna20166

Not sure if this is what you folks are referring to, but I eventually found a way to "reload/reset" the captcha (in my case after a successful form post via AJAX) by using the following data attribute on my form:

data-request-success="$('#form-id')[0].reset(); grecaptcha.reset();"

RempadDesign
RempadDesign

Hi, how can we change the 'Default text' error message that pops out if the reCaptcha is not checked and the form submited? The example here: https://snag.gy/2NXP7S.jpg

Thank you in advance.

RempadDesign
RempadDesign

alxy said:

Hi, thanks for the feedback. Could you further debug this? Im unsure how we could solve this issue in a good way.

If you have any idea, let me know :)

Hi all. The problem is that after Submiting the form with some ajaxField errors and check the reCaptcha it stays checked ... until these point everythings ok. The user corrects the errors in the fields, (remember that the reCaptcha (V2) stays checked) can't re-check the captcha and hit submit...but the reCaptcha throws error because eaven if it's checked the token let's say it's old and the form didn't submit.

RempadDesign
RempadDesign

We should implement something like this but I'm not sure how to integrate it in the plugin. https://stackoverflow.com/questions/30995026/google-recaptcha-fail-for-second-time-submit

info24938
info24938

@RempadDesign: I had the same problem with the annoying and confusing "Default text" error message. I've solved it as follow (alas, I had to modify a source file for the captcha plugin for this):

  1. In CaptchaMiddleware.php I commented out the line: throw new AjaxException( $response->getErrorCodes() );
  2. In the page I added an error element (with red background) #recaptchaError near the captcha, stating that the captcha has not been (correctly) checked yet.
  3. In the same page I added this block of javascript code (to be called by ReCAPTCHA when it was successfully checked). This callback then hides the #recaptchaError element.
function recaptchaCallback () { $('#recaptchaError').hide(); }

Last updated

nathan54220
nathan54220

for this issue for the temporary fix can add set timeout in the submit button

<button type="submit" class="btn btn-danger btn-lg" style="width: 250px;" id="cutomClick">Submit</button>

    $( "#cutomClick" ).click(function() {
        setTimeout(
            function() {
                grecaptcha.reset();
            }, 3000);

    });

hope can help :)

Last updated

1-13 of 13