Hey brilliant peers!
Looking for advice on adding custom javascript calls on Form Submissions in the form embed code on our website.
Goal: redirect the post-submission thank you page to different URLs based on the input fields upon form submission. (Variable landing pages)
I saw this post: https://community.hubspot.com/t5/Lead-Capture-Tools/Single-form-for-multiple-pages-multiple-thank-you-pages/m-p/494326/thread-id/6425
And read through this article: https://legacydocs.hubspot.com/docs/methods/forms/advanced_form_options
And built my first pass at the javascript code in our embed:
~~ start ~~
onFormSubmitted: function($form) {
if (
(
document.querySelector("input[name='customer_input_revenue']").value = "Over $500M"
)
) {
// if field value is a specific results, then set value of redirectUrl to a hardcoded URL I desire
redirectUrl.value = "https://aidaptive.com/nickbudincich-redirect-case-1" ;
return redirectUrl ;
} else {
// Otherwise, set value of redirectUrl to a default hardcoded URL I desire
redirectUrl.value = "https://aidaptive.com/nickbudincich-redirect-else" ;
return redirectUrl ;
}
}
~~ end ~~
(see pic)
I’m sure this is super simple, it’s just a matter of syntax and I’m not a pro.
Is there someone who can point me to the right resource? Or someone who can comment on the right syntax?
The logic is straightforward:
- Upon form Submitted >
- IF ( field input is ___ )
- THEN (set the redirect URL to case 1 )
- OTHERWISE (set to default redirect URL)
Thank you SO much!