Blog, Website & Page Publishing

RMaradan
Participant

Redirecting a HubSpot form to a thank you page based on a form field

I’m trying to configure a HubSpot form to redirect to a URL if a  field is checked. I also want the same form to redirect to a different URL if the field is unchecked.

 

How would I make the redirectURL into a conditional statement based on whether or not a box is checked?


Tried a few options but now out of ideas. At one stage I got it to redirect, but wouldn't pick up any form submissions via Safari.

 

Failed attempt below.

 

<!--[if lte IE 8]>

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script>

<![endif]--><script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script><script>

hbspt.forms.create({

              portalId: "*******",

              formId: ************",

              onFormSubmitted: function($form) {

            if($form.find('input[name="property name"]').prop('checked')){

                window.location.href = "URL 1";

            }else{

                window.location.href = "URL2";

            }

        }

});

</script>

0 Upvotes
3 Replies 3
CAnderson716
Contributor | Elite Partner
Contributor | Elite Partner

Redirecting a HubSpot form to a thank you page based on a form field

Hi @RMaradan, I found this article which describes the how-to for exactly what you are trying to do. Stephanie O'Gay Garcia uses the Form Event Listener to accomplish the thank you page redirecting based on a form field. 

 

Here is the link to the article: https://www.stephanieogaygarcia.com/hubspot-website-development/redirect-a-hubspot-form-to-a-thank-y... 

 

The article shares the code to use along with screenshots in HubSpot of how to make the form field the unique identifier.

TAlfrink
Participant

Redirecting a HubSpot form to a thank you page based on a form field

Note that the solution in the article is only available for marketing / cms hub professional and enterprise

0 Upvotes
RMaradan
Participant

Redirecting a HubSpot form to a thank you page based on a form field

Hey! Thanks for sharing.

The article got me about 9/10ths of the way there, the main stumbling block is that article is for dropdown vs checkbox - and I have thus far struglged to get it to replicate perfectly using the checkbox functionality.

0 Upvotes