1var c4p_cnt_form = { 2 sending: false, 3 translations : {'german' :{'empty' : "Bitte alle Pflichtfelder ausfüllen", 4 'sending' : "Bitte warten ....", 5 'success' : "Die Nachricht wurde erfolgreich gesendet.", 6 'fail' : "Leider konnte die Nachricht NICHT gesendet werden.", 7 'send' : "Nachricht versenden"}, 8 'english' : {'empty' : "Please enter all required fields", 9 'sending' : "Please wait ....", 10 'success' : "Your message has been sent.", 11 'fail' : "Sorry, your message was NOT successfully sent.", 12 'send' : "Send message"}, 13 'french' : {'empty' : "Vérifiez qu'au moins un champs soit remplis", 14 'sending' : "Envoi en cours. Veuillez patienter.", 15 'success' : "Votre message a bien été envoyé. Merci.", 16 'fail' : "L'envoi du message a échoué.", 17 'send' : "Envoyer le message"}, 18 'spanish' : {'empty' : "Todos los campos obligatorios deben ser completados.", 19 'sending' : "Se está enviando el mensaje", 20 'success' : "El mensaje se ha enviado correctamente.", 21 'fail' : "Desafortunadamente el mensaje NO pudo ser enviado.", 22 'send' : "Enviar mensaje"} 23 }, 24 init : function(id) { 25 const baseForm = document.querySelector("#c4p_cnt_contactform_" + id); 26 const submitButton = baseForm.querySelector(".send_button>button"); 27 const language = baseForm.dataset.language; 28 var base_form = $("#c4p_cnt_contactform_" + id); 29 // base_form.find(".radio_element>label").on("click", function(event) {if (event.originalEvent.originalTarget.nodeName.toLowerCase() !== "a") $(this).prev().trigger("click");}); 30 31 // submitButton.onclick = c4p_cnt_form.onSubmit; 32 if (submitButton.innerHTML === "") 33 submitButton.innerHTML = c4p_cnt_form.translations[language]['send']; 34 35 baseForm.querySelector(".waitframe").onclick = c4p_cnt_form.onResetForm; 36 37 // baseForm.onsubmit = function(e) { 38 // alert("TEST!"); 39 // e.preventDefault(); 40 // return false; 41 // } 42 43 baseForm.addEventListener("submit", (e) => { 44 e.preventDefault(); 45 c4p_cnt_form.onSubmit.call(submitButton); 46 return false; 47 }) 48 }, 49 onChange : function(e) { 50 }, 51 onKeypress : function(e) { 52 }, 53 onResetForm : function() { 54 if (c4p_cnt_form.sending) 55 return; 56 const baseForm = this.closest(".c4p_cnt_form"); 57 baseForm.querySelectorAll('input[type="text"],textarea').forEach(element => element.value = ""); 58 baseForm.querySelectorAll('input[type="radio"],input[type="checkbox"]').forEach(element => element.checked = false); 59 baseForm.querySelectorAll("select").forEach(element => element.selectedIndex = 0); 60 baseForm.querySelector(".waitframe").style.display = 'none'; 61 }, 62 onSubmit : function() { 63 const baseForm = this.closest(".c4p_cnt_form"); 64 const waitFrame = baseForm.querySelector(".waitframe"); 65 const language = baseForm.dataset.language; 66 const useAlert = parseInt("0" + baseForm.dataset.useAlert, 10) === 1; 67 var base_form = $(this).parents(".c4p_cnt_form"); 68 69 // baseForm.querySelector("input").style.border = "1px solid red"; 70 // baseForm.querySelector("input").setCustomValidity("Bitte wöhlen Sie mindestens eine der Optionen aus."); 71 // console.log(baseForm.querySelector("input").reportValidity()); 72 // return; 73 // Status setzen 74 baseForm.querySelectorAll(".error").forEach(element => element.classList.remove("error")); 75 // Formular auslesen 76 var form_fields = []; 77 form_fields.push({name: "content_id", value: base_form.get(0).id.substr(20)}); 78 base_form.find(':input').each(function(i) { 79 // Sonstige 80 if (this.type != "checkbox" && this.type != "radio") { 81 var name = this.name; 82 var value = $(this).data("empty") == 1 ? "" : this.value; 83 if (name != "") { 84 form_fields.push({name: name, value: value}); 85 } 86 } 87 }); 88 base_form.find(":checked").filter("input").each(function(i) { 89 var name = this.name; 90 if (this.type == "checkbox") 91 name += "[]"; 92 if (name != "") 93 form_fields.push({name: name, value: this.value}); 94 }); 95 96 let hasError = false; 97 baseForm.querySelectorAll("[data-required='1'][value='0']").forEach(element => { 98 console.log(form_fields.find(field => field.name === element.name + "[]")); 99 if (!(form_fields.find(field => field.name === element.name + "[]"))) { 100 element.setCustomValidity("Bitte wöhlen Sie mindestens eine der Optionen aus."); 101 element.reportValidity(); 102 element.setCustomValidity(""); 103 hasError = true; 104 } 105 }); 106 107 if (hasError) 108 return; 109 110 c4p_cnt_form.sending = true; 111 waitFrame.style.display = 'block'; 112 waitFrame.querySelector(".text").innerHTML = c4p_cnt_form.translations[language]['sending']; 113 114 $.post("/system/content/contactform/ajax.email_form.php", $.param(form_fields), function(data) { 115 c4p_cnt_form.sending = false; 116 if (data['error_code'] == 1) { 117 alert(c4p_cnt_form.translations[language]['empty']);
118 for(i in data['fields']) { 119 base_form.find('[name="field_' + data['fields'][i] + '"]').parents(".field").parent().addClass("error"); 120 } 121 base_form.find(".waitframe").hide(); 122 } else if (data['error_code'] == 2) { 123 base_form.find(".waitframe").find(".text").html(c4p_cnt_form.translations[language]['fail']); 124 if (useAlert) 125 alert(c4p_cnt_form.translations[language]['fail']); 126 } else { 127 base_form.find(".waitframe").find(".text").html(c4p_cnt_form.translations[language]['success']); 128 if (useAlert) 129 alert(c4p_cnt_form.translations[language]['success']); 130 } 131 }, "json"); 132 } 133}; 134 135$(function() { 136 function initContentContactform() { 137 $("[data-contactform-id]").each(function() { 138 if ($(this).data("initialized") !== true) { 139 c4p_cnt_form.init(parseInt("0" + $(this).data("contactformId"), 10)); 140 $(this).data("initialized", true); 141 } 142 }); 143 } 144 initContentContactform(); 145 $(document).on("p4-init-content-contactform", initContentContactform); 146});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.