CMS Development

REVEALiO
Participant

Add customer property in Form Redirect to an external site.

We have a form that redirects to an external site. I would like to append the form redirect link with a custom customer property.

 

I went to the page that has the form and I tried to add this external link: http://order.revealio.com/revealio-book-covers-payment?affiliateid={{contact.affiliateid}}

 

Unfortunately it doesn't append the contact.affiliateid to the url when it redirects. Is there a way to do this?

 

If so, is there a way to make it conditional so that ?affiliateid= only appears if the user has that field. I can create a button by using the code below but I'd like it to work from the form.

 

Button Code:

{% if contact.affiliateid %}
<p><a class="hs-button primary" href="http://www.order.revealio.com?affiliateid={{contact.affiliateid}}" target="_blank">Order Now</a></p>
{% else %}
<p><a class="hs-button primary" href="http://www.order.revealio.com" target="_blank">Order Now</a></p>
{% endif %}

10 Replies 10
ndwilliams3
Key Advisor

Add customer property in Form Redirect to an external site.

I think I figured out a workaround.

 

You can use the form embed script with the redirectUrl parameter. On a hubpsot COS or landing page, the property is added. Not great for non-coders, but it works! I used a Custom HTML module in the template and just added the script when creating the landing page. I tested it and the property was included in the URL.

 

<!--[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: 'YOUR_PORTAL_ID',
    formId: 'THE_FORM_ID',
    redirectUrl: 'http://www.order.revealio.com?affiliateid={{contact.affiliateid}}'
  });
</script>

 

REVEALiO
Participant

Add customer property in Form Redirect to an external site.

Wow, I will give it a try, do you know if there is a way to make it work conditionally? In my button code I have it use the standard URL if the user doesn't have an affiliate ID and the "?affiliateid=" url if they do. I know I can do an if statement in Javascript but how do I set the variable to use in JS using HubL?

0 Upvotes
ndwilliams3
Key Advisor

Add customer property in Form Redirect to an external site.

i haven't tested conditionally. But, I think a HUBL if statement would work.

0 Upvotes
ndwilliams3
Key Advisor

Add customer property in Form Redirect to an external site.

I tested with HUBL conditional.

<!--[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>
var query = {% if contact.affiliateid %}"?affiliateid={{contact.affiliateid}}"{%else%}""{% endif %} hbspt.forms.create({ portalId: 'YOUR_PORTAL_ID', formId: 'THE_FORM_ID', redirectUrl: 'http://www.order.revealio.com' + query }); </script>

 

Pabbiz
Participant

Add customer property in Form Redirect to an external site.

Thank you for your solution @ndwilliams3 this is great!

 

Just wondering if you had a solution to set internal value according to the contact answer. For example:

if {{contact.affiliateid}} = ABC

then the query = QWE

 

therefore URL = http://www.order.revealio.com?QWE      (instead of ABC)

 

Thanks

Pablo

0 Upvotes
ndwilliams3
Key Advisor

Add customer property in Form Redirect to an external site.

var query = {% if contact.affiliateid %}"?affiliateid={% if contact.affiliateid == "ABC" %}QWE{%else%}{{ contact.affiliateid }}{% endif %}"{%else%}""{% endif %}
ndwilliams3
Key Advisor

Add customer property in Form Redirect to an external site.

just noticed quotes around ABC need to be single quotes not double.

0 Upvotes
BorjaInbound
Participant

Add customer property in Form Redirect to an external site.

Hello Guys,

 

Thanks  for the information you gave in the above posts.

 

Do you think we can use this method to conditionally change the URL which should the form redirect to?

 

Our use case is that we have a client that has "private pages" for customers, each private page is for one particular group of customers, so, is there any way using HUBL that if the Field X has the value Y, the redirect should be to page Z?

 

Thanks in advance for the help 🙂

 

Kind  regards!

0 Upvotes
relabidin
HubSpot Alumni
HubSpot Alumni

Add customer property in Form Redirect to an external site.

Wow, that is great! Nice work as always @ndwilliams3

0 Upvotes
relabidin
HubSpot Alumni
HubSpot Alumni

Add customer property in Form Redirect to an external site.

Hi @REVEALiO,

 

Are you expecting the actual text of the URL to be changed from the personalization to the affiliate ID when the user reaches the next page? If so, the actual text of the URL will not change and the token {{contact.affiliateid}} will remain. However, if your external page has the HubSpot Tracking Code on it and you place {{contact.affiliateid}} in the body of the page, then it should populate with the contact's affiliate ID given that they provided this information in their form submission, or if they already had a value for this property and they have a HubSpot tracking cookie that relates them back to their contact record. I encourage you to check out this post from our knowledge base on auto-populating form fields via query string for some more detail on this: https://knowledge.hubspot.com/articles/kcs_article/forms/can-i-auto-populate-form-fields-through-a-q...

 

As for making the redirect URL conditionally include the query parameter for affiliate ID, this is definitely not a feature that is available in HubSpot at this time. 

 

Rami 

0 Upvotes