For anyone searching for a solution where you can use the redirect settings from the form:
window.addEventListener('message', event => {
if (event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') {
const input = document.querySelector('select[name="input_name"]');
const context = document.querySelector('input[name="hs_context"]');
const contextObject = JSON.parse(context.value);
const redirectUrl = contextObject.redirectUrl; // Retrieve the redirectUrl from the form settings
if (input) {
if (input.value && redirectUrl) {
window.location.href = redirectUrl + `?input_name=${input.value}`;
}
}
}
});