RE: Redirect URL using marketing page/form
Hi Reneilene Gacusan ,
To change the url to which the user is redirected after the form is submitted based on a value in the form, you would follow the basic approach suggested by Clofly, above, but first parse the form to get the value from the relevant input, and then set the window.location.href based on that value.
For example:
MsCrmMkt.MsCrmFormLoader.on("afterFormSubmit", function(event) {
// Assuming the relevant input has the id "country":
const countryInput = document.getElementById("country");
const countryValue = countryInput.value;
// Assuming the relevant input can have the values "PH" or "AU":
if (countryValue === "PH") {
window.location.href = "https://www.example.com/A";
} else if (countryValue === "AU") {
window.location.href = "https://www.example.com/B";
} else {
// Doesn't hurt to have a fallback:
window.location.href = "https://www.example.com"
}
});
Make sure your event listener is listening for the afterFormSubmit event, as opposed to formSubmit or any other event emitted by the form loader, since you want to wait until the form has been submitted and processed before sending the user elsewhere. Per the docs, the afterFormSubmit event:
Triggers on form submit after the form submission is sent to the server. It triggers only when the submission is successful. It triggers before the redirect or showing the confirmation message.