Code: Select all
} else if (currentStep === 4) {
const dietaryNotes = document.getElementById("dietaryNotes").value;
const messageToHosts = document.getElementById("messageToHosts").value;
const rsvpData = {
name: guestNameInput.value.trim(),
message: messageToHosts,
dietaryNotes: dietaryNotes,
rsvps: rsvpChoices // This includes each guest's RSVP and meal choice
};
console.log("About to fetch to Heroku endpoint...");
fetch("https://immense-plains-30838-adb516d69898.herokuapp.com/api/submit", {
method: "POST",
body: JSON.stringify(rsvpData),
headers: {
"Content-Type": "application/json"
}
})
.then(r => r.json())
.then(data => {
if (data.success) {
alert("RSVP submitted! Thanks!");
showStep(1);
form.reset();
} else {
alert("Failed to submit RSVP.");
}
})
.catch(err => {
console.error(err);
alert("Error submitting RSVP.");
});
}
});
// Initially show Step 1
showStep(1);
});