Copied to clipboard

Flag this post as spam?

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


  • MB 108 posts 397 karma points
    Sep 06, 2019 @ 13:52
    MB
    0

    Reset form after Ajax Submission

    I'm submitting an Umbraco Form using Ajax via a click event on the submit button.

    var $form = $(this);
    $.ajax({
        type: 'POST',
        success: function (result) {
            $form[0].reset();
            if (typeof grecaptcha !== 'undefined') {
                grecaptcha.reset();
            }
        }
    });
    

    It works, and clears the form and resets the grecaptcha ok, but when I then re-use the the form including the recaptcha, and submit again, the form clears all the fields and then barks about missing field values, and the only fix at that point is to refresh the entire page, rather defeating the purpose of using Ajax.

    It would seem that doing a form.reset using jQuery is not cutting it, and I need to do something else to make the form re-usable after an Ajax submit, without needing to refresh the entire page.

    Anyone have a solution for this?

Please Sign in or register to post replies

Write your reply to:

Draft