Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div>
- <div><input name="ListIds" type="hidden" value="2e3ae926-6fa9-41e4-9d5b-dc4cf24ed043"> 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> </label><br> <button onclick="submitForm(event)">Prenumerera</button></div>
- <script type="application/javascript">
- // <![CDATA[
- function submitForm(event) {
- event.preventDefault();
- var form = event.target.parentNode;
- inputs = form.childNodes;
- lists = form.querySelectorAll("[name=ListIds]");
- selectedLists = [];
- valid = true;
- for (var i = 0; i < inputs.length; i++) {
- var input = inputs[i];
- if (input.required === true) {
- if (input.type === "radio" || input.type === "checkbox" && input.checked === false) {
- valid = false;
- } else if ((input.type === "email" || input.type === "tel") && !validateType(input.type, input.value)) {
- valid = false;
- } else if (input.value === "") {
- valid = false;
- }
- }
- }
- if (valid) {
- for (var i = 0; i < lists.length; i++) {
- var list = lists[i];
- if (list.checked === true || list.type === "hidden") {
- selectedLists.push(list.value);
- }
- }
- var subscription = {
- ListIds: selectedLists,
- DoubleOptIn: {
- Issue: {
- IssueId: "d335713d-9252-4ac6-beff-aa18241c39e2"
- },
- EmailSentUrl: "http://www.erstadiakoni.se/sv/konferenshotell/Om/nyhetsbrev/verifiering/"
- },
- ConfirmationIssue: {
- IssueId: "66cad9a8-4456-4a1d-89be-204484155658"
- },
- Contact: {
- Email: form.querySelectorAll("[name=ContactEmail]")[0].value,
- FirstName: form.querySelectorAll("[name=ContactFirstName]")[0].value,
- LastName: form.querySelectorAll("[name=ContactLastName]")[0].value
- },
- 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.",
- SubscriptionConfirmedUrl: "http://www.erstadiakoni.se/sv/konferenshotell/Om/Nyhetsbrev/Bekraftelse-nyhetsbrev/"
- }
- var xhr = new XMLHttpRequest();
- xhr.onreadystatechange = function() {
- if (this.readyState == XMLHttpRequest.DONE) {
- if (this.status == 200) {
- document.location = 'http://www.erstadiakoni.se/sv/konferenshotell/Om/nyhetsbrev/verifiering/';
- } else {
- document.location = 'http://www.erstadiakoni.se/sv/konferenshotell/Om/Nyhetsbrev/felmeddelande-nyhetsbrev/';
- }
- }
- }
- xhr.open("POST", "https://ui.ungpd.com/Api/Subscriptions/ba7c63ab-3c2c-4475-a345-f1ab4d6683a2/ajax", true);
- xhr.setRequestHeader("Content-Type", "application/json");
- xhr.send(JSON.stringify(subscription));
- } else {
- 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.");
- }
- }
- function validateType(type, value) {
- if (type === "email") {
- 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})$/;
- }
- if (type === "tel") {
- var regEx = /^((\+|00)\d{1,3})\d{2,4}[\-]?(\d{3,14})$/;
- }
- return regEx.test(value);
- }
- // ]]>
- </script>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement