In the past when we were using Marketo for forms, I had the abilitiy to change the URL of the page after I submitted the form through the code that I embeded on the page.
This was immensely useful because I could reuse that javscript snippet over and over on different pages and have different redirects even though it was the same form in the system.
The rough structure of it was as follows:
<script>
<form info that has form render on page>
<url of the redirect>
</form>
</script>
Does this capability exist in Hubspot? Appreciate any and all thoughts.
can you please provide a use-case for this?
I’d say that you can technically change the URL by adding some queries to it, but from a UX perspective - why would you want to do so? Wouldn’t it be easier to simply create a redirect to a different page? Doing so would give you a clear seperation and much more usability if you’d like to change something in the future.
I actually redirect them to the SAME page but I put a querry in the URL that triggers dynamic visibility of sections.
So they fill out the form to see the content, the page refreshes, and they can then see the content, all on the same page.
See below:
<script src=“//Preferences.xxxxxxxx.com/js/forms2/js/forms2.min.js”></script>
<form id=“mktoForm_xxxx”></form>
<script>
MktoForms2.loadForm(“//Preferences.FarmJournal.com”, “xxx-xxx-xxx”, xxxx, function(form) {
//Add an onSuccess handler
form.onSuccess(function(values, followUpUrl) {
// Take the lead to a different page on successful submit, ignoring the form’s configured followUpUrl
location.href = “https://www.----.com/?queryargument=password-2025”;
// Return false to prevent the submission handler continuing with its own processing
return false;
});
});
</script>
I could take the above script and reuse it for every page that we wanted to collect info from the user before they could see the content on the page. All I had to do was swap out the URL in the script. And it was all the same form that the info collected to, instead of building a different form everytime.
thanks for the example.
I understand it better now, but at the same time, I’m starting to think that it might be overcomplicated.
I mean to have such setup, you’d need either a quite engineered JS or using only custom modules with something like “show/hide module” functionality to being able to use the smart content “query param” rule.
What you can do is using {{content.absulte_url}} to have just one script placed in the landing page template or a custom module that contains the form like
<script src="//Preferences.xxxxxxxx.com/js/forms2/js/forms2.min.js"></script>
<form id="mktoForm_xxxx"></form>
<script>
MktoForms2.loadForm("//Preferences.FarmJournal.com", "xxx-xxx-xxx", xxxx, function(form) {
//Add an onSuccess handler
form.onSuccess(function(values, followUpUrl) {
// Take the lead to a different page on successful submit, ignoring the form's configured followUpUrl
location.href = "https://{{content.absolute_url}}/?queryargument=password-2025";
// Return false to prevent the submission handler continuing with its own processing
return false;
});
});
</script>
Also it seems like you’re using Marketo forms which leads me to the thesis that you are using HubSpot pages with Marketo forms. The question would be why.
No, that won’t work because I currently can use one form and change the URL redirect on every page I place the code. Using the method you’re talking about I have to create a new form for every page that has a different redirect. I’d need 25 forms to do the work of only one as I use it now.
Thanks for the ideas though!
@RWKramer
In the case where you’re having it reveal new sections of the same page, I wouldn’t have it redirect at all. Use a thank you message and a form event listener to reveal the new section. That’s the way I did it before for clients on .
window.addEventListener('message', (event) => {
if (
event.data.type === 'hsFormCallback' &&
event.data.eventName === 'onFormSubmitted'
) {
// YOUR CODE
}
});