Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot submit with "submit JS script" #99

Open
KeithBarrows opened this issue Apr 4, 2022 · 1 comment
Open

Cannot submit with "submit JS script" #99

KeithBarrows opened this issue Apr 4, 2022 · 1 comment

Comments

@KeithBarrows
Copy link

KeithBarrows commented Apr 4, 2022

I am trying to submit the form and am having a couple of challenges:

  1. The submit button is active even when you do NOT use the captcha - form tries to submit via JS (below)
    2) If you click submit one it fails. If you click submit any number of times after that it just sits and does nothing!
function submitContactUs() {
    if (!$("#frmContactUs").valid()) {
        return;
    }

    $("#btnSubmit").prop("disabled", true);

    let data = {
        ContactType: $("input[name='ContactType']:checked")[0].value,
        FirstName: $("#FirstName").val(),
        LastName: $("#LastName").val(),
        Message: $("#Message").val(),
        AgreeToTerms: $("#AgreeToTerms")[0].checked,
        Email: $("#Email").val(),
        PhoneNumber: $("#PhoneNumber").val(),
        PhoneNumberExt: $("#PhoneNumberExt").val(),
        Product: $("#Product").val(),
        ContactReason: $("#ContactReason").val(),
        Rating: 1 // Set default to pass range validator
    };
    let area = $("#Area").val();

    $.ajax({
        url: 'ContactUs/SubmitContactUs',
        method: 'POST',
        data: data,
        beforeSend: function (request) {
            $("div.ajax_loader").show();
        },
        complete: function () {
            $("div.ajax_loader").hide();
        },
        success: function (data) {
            if (data) {
                if (data === "error") {
                    showMessage(area, "error", "ContactUs");
                }
                else {
                    window.location = data;
                }
            }
            else {
                $("#btnSubmit").prop("disabled", false);
                showMessage(area, "error", "ContactUs");
            }
        },
        error: function () {
            showMessage(area, "error", "ContactUs", null, null, true);
        }
    });
}

What is the best approach to include the postback info required to make the Controller Action work properly. Please note: with this JS code we are not even getting to the Action, we just get a 500 error happening in the Validator with no real message surfaced.

@KeithBarrows
Copy link
Author

Removed the nuget, downloaded the repo, added the project to my solution, can trace to a generic error: There was an error validating the google recaptcha response. Please try again, or contact the site owner. This is in the attribute validator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant