SIGN IT (INDIVIDUAL)
var xhr = new XMLHttpRequest(); xhr.open('GET', 'https://5gspaceappeal.page/ajaxsignatureform'); xhr.timeout = 3000; xhr.ontimeout = function (e) { window.location = "http://142.93.192.111/index.php/wrappedsignature"; }; xhr.onload = function() { if (xhr.status === 200) { var newhtmltext = xhr.responseText; document.getElementById("signatureform").innerHTML = newhtmltext; } else { alert('Fetching signature form failed. Returned status of ' + xhr.status); } }; xhr.send();
// these two functions set and remove the class is-invalid-input function set_invalid_input(elname) { var element, name, arr; element = document.getElementById(elname); name = "is-invalid-input"; arr = element.className.split(" "); if (arr.indexOf(name) == -1) { element.className += " " + name; } }
function remove_invalid_input(elname) { var element = document.getElementById(elname); element.className = element.className.replace(/\bis-invalid-input\b/g, ""); }
function validateEmail(email) { var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(String(email).toLowerCase()); }
function removeElement(elementId) { // Removes an element from the document var element = document.getElementById(elementId); if (element) { element.parentNode.removeChild(element); } }
// the postposthandler does the validation of the form // and calls post_submission if it passes. function posthandler () {
// first clear the errors var errors = []; document.getElementById("errormessages").innerHTML = ""; removeElement("aspmsg"); removeElement("wppmsg"); removeElement("ctymsg");
sigform = document.getElementById("sigform"); for (var i = 0; i < sigform.elements.length; i++) { var element = sigform.elements[i]; element.className = element.className.replace(/\bis-invalid-input\b/g, ""); } first_name = document.getElementById('first_name').value; if (first_name == '') { set_invalid_input('first_name'); errors.push("First name is required."); } last_name = document.getElementById('last_name').value; if (last_name == "") { set_invalid_input('last_name'); errors.push("Last name is required."); } city = document.getElementById('city').value; if (city == "") { set_invalid_input('city'); errors.push("City is required."); } country_id = document.getElementById('country_id').value; if (country_id == "") { set_invalid_input('country_id'); cty = document.getElementById('country_id') cty.insertAdjacentHTML( 'afterend', '
' ); errors.push("Country is required."); }
email = document.getElementById('email').value.replace(/[\ \<\>\"]/g,''); document.getElementById('email').value = email; if (email == "" || !validateEmail(email)) { set_invalid_input('email'); errors.push("Valid email is required."); }
appeal_submission_permission = document.getElementById('appeal_submission_permission').checked; if (!appeal_submission_permission) { set_invalid_input('appeal_submission_permission'); asp = document.getElementById('appeal_submission_permission') asp.insertAdjacentHTML( 'afterend', '
' ); errors.push("Appeal submission permission is required.");
}
web_publication_permission = document.getElementById('web_publication_permission').checked; if (!web_publication_permission) { set_invalid_input('web_publication_permission'); wpp = document.getElementById('web_publication_permission') wpp.insertAdjacentHTML( 'afterend', '
' ); errors.push("Web publication permission is required."); }
// get the value from a radio group profession_id = ""; var profession_ids = document.getElementsByName('profession_id'); for (var i = 0, length = profession_ids.length; i < length; i++) { if (profession_ids[i].checked) { profession_id = profession_ids[i].value; break; } } if (profession_id == 1) { var other1 = document.getElementById('profession_other_1').value; if (other1 == "") { set_invalid_input('profession_other_1'); errors.push("Please indicate your field."); } } if (profession_id == 22) { var other22 = document.getElementById('profession_other_22').value; if (other22 == "") { set_invalid_input('profession_other_22'); errors.push("Please specify your profession"); } } if (errors.length > 0) { document.getElementById("errormessages").innerHTML = "
") + "
"; return; }
post_submission();
}
function post_submission() { var xhr = new XMLHttpRequest(); sigform = document.getElementById("sigform"); formdata = serialize(sigform); //alert('http://5gspaceappeal.page/ajaxsignaturesave?' + formdata); xhr.open('POST', 'https://5gspaceappeal.page/ajaxsignaturesave?' + formdata); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onload = function() { if (xhr.status === 200) { if (JSON.stringify(xhr.responseText).includes("dupemail")) { window.location.href = "/duplicate-email"; } else { window.location.href = "/thank-you-post-signature"; //alert('Worked ok, next redirect to thankyou'); } } else if (xhr.status !== 200) {
alert('Submission failed. Returned status of ' + xhr.status); } }; // xhr.send(encodeURI('name=' + newName)); xhr.send(); }
/*! * Serialize all form data into a query string * (c) 2018 Chris Ferdinandi, MIT License, https://gomakethings.com * @param {Node} form The form to serialize * @return {String} The serialized form data */ var serialize = function (form) {
// Setup our serialized data var serialized = []; // Loop through each field in the form for (var i = 0; i < form.elements.length; i++) { var field = form.elements[i]; // Don't serialize fields without a name, submits, buttons, file and reset inputs, and disabled fields if (!field.name || field.disabled || field.type === 'file' || field.type === 'reset' || field.type === 'submit' || field.type === 'button') continue; // If a multi-select, get all selections if (field.type === 'select-multiple') { for (var n = 0; n < field.options.length; n++) { if (!field.options[n].selected) continue; serialized.push(encodeURIComponent(field.name) + "=" + encodeURIComponent(field.options[n].value)); } } // Convert field data to a query string else if ((field.type !== 'checkbox' && field.type !== 'radio') || field.checked) { serialized.push(encodeURIComponent(field.name) + "=" + encodeURIComponent(field.value)); } } return serialized.join('&'); };