65 lines
2.0 KiB
JavaScript
65 lines
2.0 KiB
JavaScript
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const steps = document.querySelectorAll('.form-step');
|
|
const nextButtons = document.querySelectorAll('.btn-next');
|
|
const prevButtons = document.querySelectorAll('.btn-prev');
|
|
const progressBar = document.querySelector('.progress-bar');
|
|
const form = document.getElementById('gtm-form');
|
|
|
|
let currentStep = 0;
|
|
|
|
function updateProgress() {
|
|
const progress = ((currentStep + 1) / steps.length) * 100;
|
|
progressBar.style.width = progress + '%';
|
|
progressBar.setAttribute('aria-valuenow', progress);
|
|
}
|
|
|
|
function showStep(stepIndex) {
|
|
steps.forEach((step, index) => {
|
|
step.classList.toggle('active', index === stepIndex);
|
|
});
|
|
currentStep = stepIndex;
|
|
updateProgress();
|
|
}
|
|
|
|
nextButtons.forEach(button => {
|
|
button.addEventListener('click', () => {
|
|
if (currentStep < steps.length - 1) {
|
|
showStep(currentStep + 1);
|
|
}
|
|
});
|
|
});
|
|
|
|
prevButtons.forEach(button => {
|
|
button.addEventListener('click', () => {
|
|
if (currentStep > 0) {
|
|
showStep(currentStep - 1);
|
|
}
|
|
});
|
|
});
|
|
|
|
form.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
const formData = new FormData(form);
|
|
|
|
fetch('submit_profile.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
document.getElementById('form-container').innerHTML = '<div class="alert alert-success">Thank you! Your GTM profile has been submitted.</div>';
|
|
} else {
|
|
alert('An error occurred: ' + data.error);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
alert('A network error occurred. Please try again.');
|
|
});
|
|
});
|
|
|
|
showStep(0);
|
|
});
|