Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.37 KB | None | 0 0
  1. <div>
  2. <div><input name="ListIds" type="hidden" value="57349fd7-49ac-4b67-92fb-aca9d4f87b40"> E-post: <input name="ContactEmail" type="email"><br><br> Förnamn: <input name="ContactFirstName" type="text"><br><br> Efternamn: <input name="ContactLastName" type="text"><br><br> <label> <input name="ConsentText" type="checkbox" value="I want to receive relevant information from X to my inbox. X shall not share or sell my personal information. I can unsubscribe at any time."> Jag vill ta emot relevant information från Ersta terrass till angiven e-postadress. Ersta terrass kommer inte att dela eller sälja mina kontaktuppgifter. Jag kan när som helst avbryta min prenumeration.<br>&nbsp;</label><br> <button onclick="submitForm(event)">Prenumerera</button></div>
  3.  
  4. <script type="application/javascript">
  5.     // <![CDATA[
  6.   function submitForm(event) {
  7.       event.preventDefault();
  8.       var form = event.target.parentNode;
  9.       inputs = form.childNodes;
  10.       lists = form.querySelectorAll("[name=ListIds]");
  11.       selectedLists = [];
  12.       valid = true;
  13.  
  14.       for (var i = 0; i < inputs.length; i++) {
  15.           var input = inputs[i];
  16.  
  17.           if (input.required === true) {
  18.               if (input.type === "radio" || input.type === "checkbox" && input.checked === false) {
  19.                   valid = false;
  20.               } else if ((input.type === "email" || input.type === "tel") && !validateType(input.type, input.value)) {
  21.                   valid = false;
  22.               } else if (input.value === "") {
  23.                   valid = false;
  24.               }
  25.           }
  26.       }
  27.  
  28.       if (valid) {
  29.  
  30.           for (var i = 0; i < lists.length; i++) {
  31.               var list = lists[i];
  32.               if (list.checked === true || list.type === "hidden") {
  33.                   selectedLists.push(list.value);
  34.               }
  35.           }
  36.  
  37.           var subscription = {
  38.               ListIds: selectedLists,
  39.               DoubleOptIn: {
  40.                   Issue: {
  41.                       IssueId: "d335713d-9252-4ac6-beff-aa18241c39e2"
  42.                   },
  43.                   EmailSentUrl: "http://www.erstadiakoni.se/sv/konferenshotell/Om/nyhetsbrev/verifiering/"
  44.               },
  45.               ConfirmationIssue: {
  46.                   IssueId: "85cba34b-9b1a-48be-896e-afa517480b55"
  47.               },
  48.               Contact: {
  49.                   Email: form.querySelectorAll("[name=ContactEmail]")[0].value,
  50.                   FirstName: form.querySelectorAll("[name=ContactFirstName]")[0].value,
  51.                   LastName: form.querySelectorAll("[name=ContactLastName]")[0].value
  52.               },
  53.               ConsentText: "I want to receive relevant information from X to my inbox. X shall not share or sell my personal information. I can unsubscribe at any time.",
  54. SubscriptionConfirmedUrl: "http://www.erstadiakoni.se/sv/konferenshotell/Om/Nyhetsbrev/Bekraftelse-nyhetsbrev/"
  55.           }
  56.           var xhr = new XMLHttpRequest();
  57.           xhr.onreadystatechange = function() {
  58.               if (this.readyState == XMLHttpRequest.DONE) {
  59.                   if (this.status == 200) {
  60.                       document.location = 'http://www.erstadiakoni.se/sv/konferenshotell/Om/nyhetsbrev/verifiering/';
  61.                   } else {
  62.                       document.location = 'http://www.erstadiakoni.se/sv/konferenshotell/Om/Nyhetsbrev/felmeddelande-nyhetsbrev/';
  63.                   }
  64.               }
  65.           }
  66.           xhr.open("POST", "https://ui.ungpd.com/Api/Subscriptions/ba7c63ab-3c2c-4475-a345-f1ab4d6683a2/ajax", true);
  67.           xhr.setRequestHeader("Content-Type", "application/json");
  68.           xhr.send(JSON.stringify(subscription));
  69.       } else {
  70.           alert("Oh snap! We were unable to submit the form. Maybe you haven't filled in all required fields or a field has a non valid value. Give it one more go.");
  71.       }
  72.   }
  73.  
  74.   function validateType(type, value) {
  75.           if (type === "email") {
  76.               var regEx = /^(([a-zA-Z0-9_\-\+]+)|([a-zA-Z0-9_\-\+]+)([a-zA-Z0-9_\-\+\.]*)([a-zA-Z0-9_\-\+]+))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,63}|[0-9]{1,63})$/;
  77.           }
  78.           if (type === "tel") {
  79.               var regEx = /^((\+|00)\d{1,3})\d{2,4}[\-]?(\d{3,14})$/;
  80.           }
  81.           return regEx.test(value);
  82.       }
  83.       // ]]>
  84. </script>
  85. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement