Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Levente Kosa 136 posts 352 karma points
    Feb 01, 2020 @ 14:01
    Levente Kosa
    0

    Checkbox and recaptcha validation ignored

    Hi,

    I have two forms on my page. A simple and one in a modal view. If I add these scripts to the page:

    <script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js"></script>
    
    
    
    
    <script src="https://ajax.aspnetcdn.com/ajax/mvc/5.2.3/jquery.validate.unobtrusive.min.js"></script>
    

    the checkbox and recaptcha mandatoriness get ignored.

    I have Umbraco v7.13.1. My js code:

    $(document).ready(function () {
        //Intercept Submit button in order to make ajax call instead of a postback
        var $modalForm = $('.modal .umbraco-forms-form form');
        $modalForm.preventDoubleSubmission();
    
        console.log('preventDoubleSubmission');
    });
    
    // jQuery plugin to prevent double submission of forms
    jQuery.fn.preventDoubleSubmission = function () {
        $(this).on('submit', function (e) {
            console.log('submit');
            e.preventDefault();
    
            var $form = $(this);
            var $brochure = $form.parents(".modal").data("brochure");
    
            if ($form.data('submitted') === true) {
                console.log('submitted');
                // Previously submitted - don't submit again
            } else {
                if ($form.valid()) {
                    console.log('valid');
                    // Mark it so that the next submit can be ignored
                    $form.data('submitted', true);
                    // Disabled button intil post
                    $form.find('[name="submitbtn"]').prop('disabled', true);
    
                    // Make ajax call form submission
                    $.ajax({
                        url: $form.attr('action'),
                        type: 'POST',
                        cache: false,
                        data: $form.serialize(),
                        success: function (result) {
                            console.log('success');
    
                            var thankYouMessage = $(result).find('.umbraco-forms-submitmessage').first();
                            //Handles edge case where Recaptcha wasn't checked
    
                            if (thankYouMessage.length == 0) {
                                console.log('error');
                                $(result).find('.field-validation-error').each(function (i, v) {
                                    console.log($(v).text());
                                });
    
                                $form.data('submitted', false);
                                $form.find('[name="submitbtn"]').prop('disabled', false);
                            }
                            else {
                                $form.html(thankYouMessage);
                                console.log('thanks');
                            }
                        }
                    });
                }
            }
        });
    
        // Keep chainability
        return this;
    };
    

    Also weird when I loop through the errors, the checkbox and captcha errors appears in console, but the actual nodes (span.field-validation-error) are missing:

    Some help would be great.

  • Damiaan 442 posts 1302 karma points MVP 6x c-trib
    Feb 02, 2020 @ 14:25
    Damiaan
    0

    Hi Levente

    Could you share some HTML? Or is your trial already somewhere online?

    I guess the Recaptcha is not inside the html FORM tag which disregards the MVC validation.

    Kind regards

  • Levente Kosa 136 posts 352 karma points
    Feb 03, 2020 @ 13:10
    Levente Kosa
    0

    Hi Damiaan,

    Thanks for the response. You can test here on staging: https://staging.fortescuegardens.co.uk/ At the bottom of the page there is a download brochure button. When you fill in Recaptcha is getting ignored, however in console log you can see the error message: "Please confirm you are a human". Above there is the error message span which should be there but it isn't: span.field-validation-error

    It's a standard Recaptcha field in Umbraco forms, so yes, it's inside the form tag.

    Amy more ideas maybe?

    PS: If I remove

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.11/jquery.validate.unobtrusive.min.js"></script>
    from the page, the recaptcha is working. But I need for the client form of course.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies