Skip to content

Commit 80169d6

Browse files
committed
new form system added
1 parent 3d182b6 commit 80169d6

File tree

3 files changed

+46
-38
lines changed

3 files changed

+46
-38
lines changed

layouts/_default/single.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ <h2 class="text-xl mt-9">{{ .Params.content.title }}</h2>
2626

2727
<div class="flex items-center justify-start gap-3 my-5 flex-wrap">
2828
<a
29-
href="/start-trial?service={{ .Params.content.name }}"
29+
href="/start-trial?service_id={{ .Params.content.id }}&service_name={{ .Params.content.name }}"
3030
class="rounded-md isolate bg-gradient-to-r from-[#ff80b5] to-[#9089fc] px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:opacity-70 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2">
3131
Start Free Trial
3232
</a>

layouts/page/start-trial.html

+43-35
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
{{ define "main" }}
2-
<script>
3-
let __plan_name = "Professional";
4-
</script>
52
<div class="isolate px-6 py-24 sm:py-32 lg:px-8">
63
<div class="mx-auto max-w-2xl text-center">
74
<h2 class="text-3xl font-bold tracking-tight text-gray-900 sm:text-4xl">
@@ -13,7 +10,6 @@ <h2 class="text-3xl font-bold tracking-tight text-gray-900 sm:text-4xl">
1310
</div>
1411

1512
<script>
16-
let start_trial_form_submitted = false;
1713
window.onload = function () {
1814
let referralCode = localStorage.getItem("referral-code");
1915

@@ -25,55 +21,66 @@ <h2 class="text-3xl font-bold tracking-tight text-gray-900 sm:text-4xl">
2521
document.getElementById("referral-code").value = referralCode;
2622
}
2723

28-
const serviceName = getQueryParam("service");
24+
const serviceId = getQueryParam("service_id");
25+
const serviceName = getQueryParam("service_name");
2926

30-
if (serviceName) {
27+
if (serviceId && serviceName) {
28+
document.getElementById("service-id").value = serviceId;
3129
document.getElementById("service-name").value = serviceName;
3230
} else {
3331
window.location = "/";
3432
}
3533
};
3634

37-
function loading() {
35+
async function submitForm(form) {
36+
event.preventDefault();
37+
3838
const btn = document.getElementById("submit-btn");
3939

4040
btn.disabled = true;
4141
btn.textContent = "Submitting...";
42-
}
4342

44-
function onFormSubmit() {
45-
if (start_trial_form_submitted) {
46-
const plans = {
47-
startup: "https://buy.stripe.com/4gwaF0bWd3nh2AwaEF",
48-
professional: "https://buy.stripe.com/00gaF0gct9LF6QM6oq",
49-
business: "https://buy.stripe.com/cN29AW4tL9LFeje7sv",
50-
enterprise: "https://buy.stripe.com/dR614q2lD9LF0so6os",
51-
};
43+
const formData = new FormData(form);
44+
const requestData = Object.fromEntries(formData.entries());
45+
46+
delete requestData.terms_and_conditions;
5247

53-
__plan_name = __plan_name.toLowerCase();
48+
requestData.plan = requestData.plan.toLowerCase();
5449

55-
const paymentLink = plans[__plan_name] || plans.professional;
50+
try {
51+
const response = await fetch(
52+
"https://admin.octabyte.app/items/customer_services",
53+
{
54+
method: "POST",
55+
headers: {
56+
"Content-Type": "application/json",
57+
},
58+
body: JSON.stringify(requestData),
59+
},
60+
);
61+
62+
if (!response.ok) {
63+
throw new Error("There was an error submitting the form.");
64+
}
5665

5766
localStorage.removeItem("referral-code");
58-
window.location = paymentLink;
67+
68+
const data = await response.json();
69+
const session_url = data.data.session_url;
70+
window.location = session_url;
71+
} catch (error) {
72+
console.error("Error submitting form:", error);
73+
alert("There was an error submitting the form.");
5974
}
6075
}
6176
</script>
6277

63-
<iframe
64-
name="hidden_iframe"
65-
id="hidden_iframe"
66-
style="display:none;"
67-
onload="onFormSubmit()"></iframe>
68-
6978
<form
70-
action="https://docs.google.com/forms/d/e/1FAIpQLSeaxk4nWWZZw6LvQPPS80PuSOfEC3rmAWPtzOYapioaYguzqQ/formResponse"
7179
method="post"
72-
target="hidden_iframe"
73-
onsubmit="start_trial_form_submitted = true; loading()"
80+
onsubmit="submitForm(this)"
7481
class="mx-auto mt-16 max-w-xl sm:mt-20">
7582
<!-- Referral Code -->
76-
<input id="referral-code" type="hidden" name="entry.1415040235" />
83+
<input id="referral-code" type="hidden" name="referral_code" />
7784

7885
<div class="grid grid-cols-1 gap-x-8 gap-y-6 sm:grid-cols-2">
7986
<div>
@@ -85,7 +92,7 @@ <h2 class="text-3xl font-bold tracking-tight text-gray-900 sm:text-4xl">
8592
<div class="mt-2.5">
8693
<input
8794
type="text"
88-
name="entry.973173615"
95+
name="first_name"
8996
id="first-name"
9097
autocomplete="given-name"
9198
placeholder="John"
@@ -102,7 +109,7 @@ <h2 class="text-3xl font-bold tracking-tight text-gray-900 sm:text-4xl">
102109
<div class="mt-2.5">
103110
<input
104111
type="text"
105-
name="entry.876595051"
112+
name="last_name"
106113
id="last-name"
107114
autocomplete="family-name"
108115
placeholder="Smith"
@@ -120,7 +127,7 @@ <h2 class="text-3xl font-bold tracking-tight text-gray-900 sm:text-4xl">
120127
<div class="mt-2.5">
121128
<input
122129
type="email"
123-
name="entry.943957029"
130+
name="admin_email"
124131
id="email"
125132
autocomplete="email"
126133
placeholder="Please provide valid email address to receive credentials"
@@ -137,7 +144,7 @@ <h2 class="text-3xl font-bold tracking-tight text-gray-900 sm:text-4xl">
137144
<div class="mt-2.5">
138145
<input
139146
type="tel"
140-
name="entry.621899747"
147+
name="phone_number"
141148
id="phone-number"
142149
autocomplete="tel"
143150
placeholder="+1 (555) 987-6543"
@@ -151,9 +158,10 @@ <h2 class="text-3xl font-bold tracking-tight text-gray-900 sm:text-4xl">
151158
Service Name
152159
</label>
153160
<div class="mt-2.5">
161+
<input type="hidden" id="service-id" name="service_id" />
154162
<input
155163
type="text"
156-
name="entry.2107164949"
164+
name="service_name"
157165
id="service-name"
158166
required
159167
readonly
@@ -184,7 +192,7 @@ <h2 class="text-3xl font-bold tracking-tight text-gray-900 sm:text-4xl">
184192
<div class="flex h-5 items-center">
185193
<input
186194
id="terms-and-conditions"
187-
name="terms-and-conditions"
195+
name="terms_and_conditions"
188196
type="checkbox"
189197
required
190198
class="h-4 w-4 cursor-pointer rounded border-gray-300 text-indigo-600 focus:ring-indigo-500" />

layouts/partials/trial/machine-type.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<script>
1010
document.addEventListener("DOMContentLoaded", function () {
1111
const radioButtons = document.querySelectorAll(
12-
"input[type='radio'][name='entry.1848613537']",
12+
"input[type='radio'][name='plan']",
1313
);
1414

1515
radioButtons.forEach((radio) => {
@@ -62,7 +62,7 @@
6262
{{ end }}">
6363
<input
6464
type="radio"
65-
name="entry.1848613537"
65+
name="plan"
6666
value="{{ $option.label }}"
6767
class="sr-only"
6868
{{ if eq $index 1 }}checked{{ end }}

0 commit comments

Comments
 (0)