-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestform.html
More file actions
79 lines (72 loc) · 1.94 KB
/
testform.html
File metadata and controls
79 lines (72 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"
type="text/javascript"
></script>
<script defer>
$("#current-page").val(location.href);
var datamail;
$(document).ready(function () {
$("form#wf-form-Test-Form").on("submit", function (event) {
console.log("Hello");
var query_string = $(this).serialize();
console.log(query_string);
var form_data = objectFromWebFlowQuerystring(query_string);
console.log(form_data);
datamail = form_data;
form_data["Current Page"] = window.location.href;
form_data.form_name = "Payment Form Adult";
hitWebhook(
form_data,
(url = "https://webhook.site/1a2f6d8b-7f79-40b6-a899-f14c238dc10a")
);
event.preventDefault();
return false;
});
function objectFromWebFlowQuerystring(
query_string,
required_keys = [
"Child-s-Name",
"Phone",
"City",
"Class",
"Current Page",
"LeadSource",
"parental-expectation",
"Language-at-Home",
"email",
]
) {
var params = new URLSearchParams(query_string);
var obj = {};
for (const key of params.keys()) {
if (required_keys.includes(key)) {
obj[key] = params.get(key);
}
}
if ($("#Child-s-Name").val()) {
obj["Child's Name"] = $("#Child-s-Name").val();
}
if ($("input#WhatsappConsent:checked").length > 1) {
obj["WhatsappConsent"] = "true";
} else {
obj["WhatsappConsent"] = "false";
}
obj["LeadSource"] = "Website";
return obj;
}
function hitWebhook(form_data, url) {
$.ajax({
url: url,
data: form_data,
type: "POST",
dataType: "json",
error: function () {
console.log("error");
},
success: function (data) {
console.log("success");
},
});
}
});
</script>