Hello,
I know in HubSpot I can use 1 form for content downloads and on each of my landing pages, put a different redirect link.
However, we want to embed a form on a WordPress site and want to redirect to different content downloads. That way it can be 1 form collecting all of these submissions but we redirect to the content the person requested. Is this possible via the embed code?
HGi @JonahWilson-GK3,
Thank you for reaching out to the Community!
I wanted to tag in a couple of subject matter experts to see if they have any input on this matter:
Hi @Ian_Matt, @Mike_Eastwood, @NicoleSengers, do you have any advice for @JonahWilson-GK3? Thank you!
Cheers
Mia, Community Team
Hi @JonahWilson-GK3
Yes, you can write some JavaScript to handle the form submission.
You will need to have Marketing Hub Pro or Enterprise and you will set the form to Raw HTML.
Here’s the documentation on customising the embed code.
Have fun
Mike
Could you also create to templated Content Download form and then build a workflow to route to the redirect links based upon the “last page viewed” field. So example:
-visit content download for ebook on www.urlklink.ebook.com/ebook
-visit content download for pamphlet on www.urlink.pamphlet.com/pamphlet
Then the workflow is:
filter criteria: has submitted “Content Download form”
enter branches
if: Last Page Viewed is "www.urlklink.ebook.com/ebook " or contains “ebook”
then: redirect to “www.redirectforurlink.ebook”
unsure if the “then” functionality is available in Hubspot. I am currently trying to build this myself, and we also have Wordpress (trying to move to using Hubspot standard forms though).
For anyone else who comes across this thread, I was able to do it with this code. I copied my form’s embed code, added a comma after the formId, and added an onFormSubmitted callback. If more pages are needed you can add more “else if” sections:
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/embed/v2.js"></script>
<script>
hbspt.forms.create({
region: "YOUR-REGION",
portalId: "YOUR-ID",
formId: "YOUR-FORM-ID",
onFormSubmitted: function () {
var currentUrl = window.location.href;
var redirectUrl = '';
if (currentUrl.includes('PAGE-1-STARTING-URL')) {
redirectUrl = 'PAGE-1-REDIRECT-URL';
} else if (currentUrl.includes('PAGE-2-STARTING-URL')) {
redirectUrl = 'PAGE-2-REDIRECT-URL';
} else if (currentUrl.includes('PAGE-3-STARTING-URL')) {
redirectUrl = 'PAGE-3-REDIRECT-URL';
}
if (redirectUrl) {
window.location.href = redirectUrl;
}
}
});
</script>