Hi all we have a feedback form on one of our sites that is submitted via javascript. Submission collects data from where on the page feedback link was clicked as well as what browser and user feedback. Form works just fine, but only submit once without reloading page.
Any ideas why that would happened?
I can see in console that connection is ok but only one submission shows up.
There is another issue that seem to be effecting this form, the site configured to have 2 urls one with www and one without. For some reason Matrix picks url at random and that causes cross origin error.
Anyone came across this? Any solutions?
Form is in the footer of the website, but it is also used to provide feedback on resources by clicking feedback link next to resource https://www.aci.health.nsw.gov.au/portal/paediatric/sources It is a feedback form in a footer
Code that does it below
$(document).on("click",".feedback-btn, .feedback-btn-general", function() {
$('#paeds-feedback-form').find('form').show();
$('#paeds-feedback-form').find('#feedback-success').hide()
var feedbackType = $(this).attr("data-type"); // general / resource
var feedbackResource = $(this).attr("data-resource"); // resource / or page url
var feedbackBrowser = navigator.userAgent;
var feedbackId = $(this).attr("data-id");
$("#feedback-comments, #feedback-userinfo").val("");
$("#feedback-resource").val(feedbackResource + " | " + feedbackId);
$("#feedback-browser").val(feedbackBrowser);
$("#feedback-type").val(feedbackType);
$("#feedback-label").html(feedbackResource);
MicroModal.show('paeds-feedback-form');
});
$(document).on(“click”,"#feedback-submit", function(e) {
e.preventDefault();
var comments = $("#feedback-comments").val().replace(/\'|\"/ig,"").trim();
var userInfo = $("#feedback-userinfo").val().replace(/\'|\"/ig,"").trim();
var resource = $("#feedback-resource").val();
var browser = $("#feedback-browser").val();
var feedbackType = $("#feedback-type").val();
if(comments == "") {
$("#feedback-comments").addClass("error");
return;
}
var feedbackData = new FormData();
feedbackData.append('SQ_FORM_496868_PAGE', '1');
feedbackData.append('form_email_496868_referral_url', '');
feedbackData.append('q496868:q1', JSON.stringify(comments));//comments
feedbackData.append('q496868:q2', JSON.stringify(userInfo));//user info
feedbackData.append('q496868:q3', JSON.stringify(resource));//resource
feedbackData.append('q496868:q4', JSON.stringify(browser));//browser
feedbackData.append('q496868:q5', JSON.stringify(feedbackType));//type
feedbackData.append('form_email_496868_submit', 'Submit');
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://aci.health.nsw.gov.au/portal/paediatric/feedback', true); // removed www
xhr.send(feedbackData);
$('#paeds-feedback-form').find('form').hide();
$('#paeds-feedback-form').find('#feedback-success').show();
$("#feedback-comments, #feedback-userinfo, #feedback-resource, #feedback-browser, #feedback-type").val("");
$("#feedback-comments").removeClass("error");
$("#feedback-label").html("");
//MicroModal.show('paeds-feedback-form');