0x1998 - MANAGER
Düzenlenen Dosya: plan.js
const params = new URLSearchParams(window.location.search); const planParam = (params.get("plan") || "starter").toLowerCase(); const planName = document.getElementById("planName"); const planIntro = document.getElementById("planIntro"); const planMap = { starter: { title: "Starter", intro: "You are one step away from launching your marketing growth system with the Starter plan." }, growth: { title: "Growth", intro: "You are one step away from streamlining campaigns with the Growth plan." }, scaleplus: { title: "Scale+", intro: "You are one step away from scaling with advanced support in the Scale+ plan." } }; const activePlan = planMap[planParam] ? planParam : "starter"; const activeConfig = planMap[activePlan]; planName.textContent = activeConfig.title; planIntro.textContent = activeConfig.intro; localStorage.setItem("selected_plan", activePlan); const form = document.getElementById("planForm"); const fullName = document.getElementById("fullName"); const planEmail = document.getElementById("planEmail"); const planPhone = document.getElementById("planPhone"); const planCompany = document.getElementById("planCompany"); const planMsg = document.getElementById("planMsg"); const planStatus = document.getElementById("planStatus"); const nameRegex = /^[A-Za-z][A-Za-z\s'-]{1,39}$/; const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/; const phoneRegex = /^\+?[0-9\s-]{10,18}$/; function setErr(el, msg) { const errEl = el.parentElement.querySelector(".err") || el.nextElementSibling; el.style.borderColor = "#ff9aad"; if (errEl) errEl.textContent = msg; } function clearErr(el) { const errEl = el.parentElement.querySelector(".err") || el.nextElementSibling; el.style.borderColor = "#3b4f6f"; if (errEl) errEl.textContent = ""; } function saveFormEntry(plan, formName, data) { const dataKey = "techechi_plan_data"; const textKey = "techechi_text_file"; const grouped = JSON.parse(localStorage.getItem(dataKey) || "{}"); if (!grouped[plan]) grouped[plan] = []; const entry = { form: formName, plan, submittedAt: new Date().toISOString(), ...data }; grouped[plan].push(entry); localStorage.setItem(dataKey, JSON.stringify(grouped)); const existingText = localStorage.getItem(textKey) || ""; const line = [ `Plan: ${plan}`, `Form: ${formName}`, `Time: ${entry.submittedAt}`, `Data: ${JSON.stringify(data)}`, "-----" ].join("\n"); localStorage.setItem(textKey, existingText ? `${existingText}\n${line}` : line); } [fullName, planEmail, planPhone, planCompany, planMsg].forEach((input) => { input.addEventListener("input", () => clearErr(input)); }); form.addEventListener("submit", (event) => { event.preventDefault(); planStatus.textContent = ""; let ok = true; if (!nameRegex.test(fullName.value.trim())) { setErr(fullName, "Enter a valid full name."); ok = false; } if (!emailRegex.test(planEmail.value.trim())) { setErr(planEmail, "Enter a valid email."); ok = false; } if (!phoneRegex.test(planPhone.value.trim())) { setErr(planPhone, "Enter a valid phone number."); ok = false; } if (planMsg.value.trim().length < 10) { setErr(planMsg, "Please enter at least 10 characters."); ok = false; } if (!ok) { planStatus.textContent = "Please fix highlighted fields."; return; } saveFormEntry(activePlan, "plan_application", { fullName: fullName.value.trim(), email: planEmail.value.trim(), phone: planPhone.value.trim(), company: planCompany.value.trim(), message: planMsg.value.trim(), planTitle: activeConfig.title }); planStatus.textContent = "Application submitted successfully."; form.reset(); });
geri dön