|
| 1 | +--- |
| 2 | +--- |
| 3 | + |
| 4 | +<script src="https://www.google.com/recaptcha/api.js?render={{< recaptcha-public-key >}}"></script> |
| 5 | +<script type="module"> |
| 6 | + const contactForm = document.querySelector("#contactFormLicense"); |
| 7 | + const copyMessageCheckbox = document.querySelector("#copyMessage"); |
| 8 | + |
| 9 | + const successAlert = document.querySelector("#successAlert"); |
| 10 | + const successAlertInstance = te.Alert.getInstance(successAlert); |
| 11 | + |
| 12 | + const isTst = |
| 13 | + window.location.origin.includes("tst") || |
| 14 | + window.location.origin.includes("localhost"); |
| 15 | + |
| 16 | + const recaptchaKey = isTst |
| 17 | + ? "6LcpeIgkAAAAALdS4oKmgSPscp8ZYFLjavMstifN" |
| 18 | + : "6Ld6dIgkAAAAAIpY7wJD8aZnFAWF-S1O5HOtdItU"; |
| 19 | + |
| 20 | + const handleContactFormSubmit = (event) => { |
| 21 | + event.preventDefault(); |
| 22 | + |
| 23 | + grecaptcha.ready(function () { |
| 24 | + grecaptcha |
| 25 | + .execute(recaptchaKey, { |
| 26 | + action: "contact", |
| 27 | + }) |
| 28 | + .then(function (token) { |
| 29 | + const recaptchaResponse = |
| 30 | + document.getElementById("recaptchaResponse"); |
| 31 | + recaptchaResponse.value = token; |
| 32 | + |
| 33 | + const xhr = new XMLHttpRequest(); |
| 34 | + xhr.open( |
| 35 | + "POST", |
| 36 | + `${window.location.origin}/api/docs/dpl/contact-form/enterprise/`, |
| 37 | + true |
| 38 | + ); |
| 39 | + xhr.setRequestHeader("content-type", "application/json"); |
| 40 | + xhr.onreadystatechange = function () { |
| 41 | + if (this.readyState == 4 && this.status == 200) { |
| 42 | + successAlertInstance.show(); |
| 43 | + } |
| 44 | + }; |
| 45 | + |
| 46 | + const date = new Date().toISOString().slice(0, 19).replace("T", " "); |
| 47 | + |
| 48 | + const contactFormData = new FormData(contactForm); |
| 49 | + const formData = { |
| 50 | + userName: contactFormData.get("userName"), |
| 51 | + userMail: contactFormData.get("userMail"), |
| 52 | + teamNumber: contactFormData.get("teamNumber"), |
| 53 | + companyName: contactFormData.get("companyName"), |
| 54 | + userMail: contactFormData.get("userMail"), |
| 55 | + projectBudget: contactFormData.get("projectBudget"), |
| 56 | + userMessage: contactFormData.get("userMessage"), |
| 57 | + copyMessage: copyMessageCheckbox.checked, |
| 58 | + |
| 59 | + mailSubject: "MDB License Contact Form", |
| 60 | + mailSource: "Tailwind License Page", |
| 61 | + }; |
| 62 | + |
| 63 | + xhr.send( |
| 64 | + JSON.stringify({ |
| 65 | + mail: formData.mailToSend, |
| 66 | + name: formData.userName, |
| 67 | + fromEmail: formData.userMail, |
| 68 | + subject: formData.mailSubject, |
| 69 | + source: formData.mailSource, |
| 70 | + phone: "", |
| 71 | + projectBudget: formData.projectBudget, |
| 72 | + companyName: formData.companyName, |
| 73 | + teamNumber: formData.teamNumber, |
| 74 | + contactMethod: "", |
| 75 | + body: formData.userMessage, |
| 76 | + copy: formData.copyMessage, |
| 77 | + date: date, |
| 78 | + recaptchaResponse: recaptchaResponse.value, |
| 79 | + }) |
| 80 | + ); |
| 81 | + }); |
| 82 | + }); |
| 83 | + }; |
| 84 | + |
| 85 | + contactForm.addEventListener("submit", handleContactFormSubmit); |
| 86 | +</script> |
0 commit comments