/* ============================== Contact Form Property Insights ============================== */ (function(){ const form = document.querySelector(".PIGUIDEForm"); if(!form) return; const steps = Array.from(form.querySelectorAll(".PIGUIDEStep")); const nextBtn = form.querySelector(".PIGUIDENext"); const backBtn = form.querySelector(".PIGUIDEBack"); const submitBtn = form.querySelector(".PIGUIDESubmit"); let currentStep = 0; function showStep(index){ steps.forEach((step,i)=>{ step.classList.toggle("active", i === index); }); backBtn.style.display = index === 0 ? "none" : "block"; nextBtn.style.display = index === steps.length - 1 ? "none" : "block"; submitBtn.style.display = index === steps.length - 1 ? "block" : "none"; } function validateStep(){ const step = steps[currentStep]; const requiredInputs = step.querySelectorAll("input[required], select[required]"); for(const input of requiredInputs){ if(!input.value.trim()){ input.focus(); input.reportValidity(); return false; } } return true; } nextBtn.addEventListener("click", function(){ if(!validateStep()) return; if(currentStep < steps.length - 1){ currentStep++; showStep(currentStep); } }); backBtn.addEventListener("click", function(){ if(currentStep > 0){ currentStep--; showStep(currentStep); } }); form.addEventListener("submit", function(e){ e.preventDefault(); if(!validateStep()) return; submitBtn.disabled = true; submitBtn.textContent = "Submitting..."; const formData = new FormData(form); fetch(form.action,{ method:"POST", body:formData, headers:{ "Accept":"application/json" } }) .then(function(response){ if(response.ok){ form.innerHTML = `
SUCCESSFULLY SUBMITTED

Thank You!

Your request has been submitted successfully. We will contact you shortly with personalised property advice.

`; }else{ throw new Error(); } }) .catch(function(){ alert("Something went wrong. Please try again."); submitBtn.disabled = false; submitBtn.textContent = "Request Consultation"; }); }); showStep(currentStep); })();