- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Unique Thank You page based on form checkbox
SOLVESep 11, 2018 5:18 PM
I’m trying to configure a HubSpot form to redirect to a URL if the “I’m a current customer” 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?
Example:
If
I’m a current customer [is checked]
Then
Redirect to ‘google.com’
Else If
I’m a current customer [is NOT checked]
Redirect to ‘thank-you-page’
This is what I tried but unfortunately did not yield results.
<!--[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: "########", onFormSubmit: function($form) { var choice = $('input[value="current_giving_customer"]').prop('checked', true).change(); if (choice == 'true') { window.location = "https://google.com/"; } else if (choice == 'false'){ window.location = "https://npr.org"; } } }); </script>
Thanks for your help!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Accepted Solutions
Sep 12, 2018 7:30 AM - edited Sep 13, 2018 7:19 AM
@priscillam - You're on the right track. Just a few tweaks to your code. See the $form being passed through the callback function?
1. You should use that element to find the inputs of the form. eg. $form.find()
2.
$('input[value="current_giving_customer"]')
This is incorrect, you want to find input by name or id
$('input[name="current_giving_customer"]')
3. I don't think it's good practice to evaluate a checked against the string 'true'; it should be just true
Try this code instead:
<!--[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: "########", onFormSubmit: function($form) { if($form.find('input[name="current_giving_customer"]').prop('checked')){ window.location.href = "https://google.com/"; }else{ window.location.href = "https://npr.org"; }
} }); </script>
If this answer helped, please, mark as solved 😄
tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.
Drop by and say Hi to me on slack.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content