<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Include URL Parameters In Redirect URL After Form Submission in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Include-URL-Parameters-In-Redirect-URL-After-Form-Submission/m-p/478851#M45939</link>
    <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/79081"&gt;@Xfixium&lt;/a&gt;&amp;nbsp;Need help passing specific fields from the form as URL query parameters&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Hey,&lt;/P&gt;&lt;P&gt;I found your solution helpful but not sure how to implement it. We want to pass specific fields from the form as URL query parameters. Can you help?&lt;/P&gt;</description>
    <pubDate>Fri, 13 Aug 2021 12:55:51 GMT</pubDate>
    <dc:creator>MdFarhan</dc:creator>
    <dc:date>2021-08-13T12:55:51Z</dc:date>
    <item>
      <title>Include URL Parameters In Redirect URL After Form Submission</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Include-URL-Parameters-In-Redirect-URL-After-Form-Submission/m-p/240338#M19234</link>
      <description>&lt;P&gt;HubSpot cannot natively add any parameters to a redirect URL that the user is sent to after submitting a form (sadly). So we created some javascript that essentially waits until the user’s contact record gets populated with data and then redirects to the url adding the contact info as needed.&lt;/P&gt;
&lt;P&gt;It works, but sometimes we are getting stuck in a loop where it’s not redirecting (presumably because it’s still waiting for the contact info to get populated).&lt;/P&gt;
&lt;P&gt;This is being used on a HS landing page with a native form. It’s being added in the sourcecode of the submission message. Again, it does work. It just sometimes stalls out in a loop waiting for the user data to populate.&lt;/P&gt;
&lt;P&gt;Here’s the code we are using. I’m wondering if anybody has suggestions on improving this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;script&amp;gt;// &amp;lt;![CDATA[
$(function() {
    var personalizedDiv = $("#personalized-div");
    var personalizedInfo = {};
    personalizedInfo['firstname'] = (personalizedDiv.data("firstname"))?personalizedDiv.data("firstname"):"";
    personalizedInfo['lastname'] = (personalizedDiv.data("lastname"))?personalizedDiv.data("lastname"):"";
    personalizedInfo['company'] = (personalizedDiv.data("company"))?personalizedDiv.data("company"):"";
    personalizedInfo['email'] = (personalizedDiv.data("email"))?personalizedDiv.data("email"):"";
    personalizedInfo['phone'] = (personalizedDiv.data("phone"))?personalizedDiv.data("phone"):"";
    
    
    
    var err = 0;
    for (var val in personalizedInfo) {
        console.log(personalizedInfo[val]);
        if(personalizedInfo[val].length == 0) {
            err++;
        }
    }
    
    
    if(err == 0) {
        window.location.href = "http://site.com/schedule-a-tour?name="+personalizedInfo['firstname'] +" "+ personalizedInfo['lastname']+"&amp;amp;email="+personalizedInfo['email']+"&amp;amp;company="+personalizedInfo['company']+"&amp;amp;phone="+personalizedInfo['phone']+"&amp;amp;skip=1";
    } else {
        setTimeout(function() { 
            location.reload();
        }, 6000);
    }
});
// ]]&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;div id="personalized-div" data-firstname="{{contact.firstname}}" data-lastname="{{contact.lastname}}" data-email="{{contact.email}}" data-company="{{contact.company}}" data-phone="{{contact.phone}}"&amp;gt;&amp;amp;nbsp;&amp;lt;/div&amp;gt;
Please wait while we redirect you to our scheduling system ...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Nov 2016 01:13:55 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Include-URL-Parameters-In-Redirect-URL-After-Form-Submission/m-p/240338#M19234</guid>
      <dc:creator>lloydsilver</dc:creator>
      <dc:date>2016-11-30T01:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Include URL Parameters In Redirect URL After Form Submission</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Include-URL-Parameters-In-Redirect-URL-After-Form-Submission/m-p/240339#M19235</link>
      <description>&lt;P&gt;This a way that I did it, it’s cookie based and basically works by setting the HubSpot page to redirect into itself. So when the submit button for a form is clicked, the code gets all the form field data, and appends it to the desired redirect url. It saves this url in a cookie. Then when the page redirects into itself, if the cookie is not empty, it redirects to the url saved in the cookie.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;function getCookie(cname) {
   var name = cname + "=";
   var decodedCookie = decodeURIComponent(document.cookie);
   var ca = decodedCookie.split(';');
   for(var i = 0; i &amp;lt;ca.length; i++) {
       var c = ca[i];
       while (c.charAt(0) == ' ') {
           c = c.substring(1);
       }
       if (c.indexOf(name) == 0) {
           return c.substring(name.length, c.length);
       }
   }
   return "";
}

var url = getCookie("UrlWithParameters");
if(url != "") {
   javascript:void(document.cookie = "UrlWithParameters=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;");
   window.location = url;
}

$(function () {
   $(window).load(function(){
       $("form.hs-form").live("submit", function (e) {
           var appendFields = function (url, values) {
               var data = {};
               $.each(values, function (i, item) {
                   if (item.name !== "hs_context") {
                       data[item.name] = item.value;
                   }
               });
               
               if (url.match(/\?/)) {
                   return url + "&amp;amp;" + encodeURIComponent($.param(data));
               } else {
                   return url + "?" + encodeURIComponent($.param(data));
               }
           };
           
           var $form = $(this);
           var apiUrl = $form.attr("action");
           var $hsContext = $("input[name='hs_context']", $form);
           var hsContext = JSON.parse($hsContext.val());
           var redirect = 'https://your_base_url.com';
           hsContext.redirectUrl = appendFields(redirect, $form.serializeArray());
           $hsContext.val(JSON.stringify(hsContext));
           javascript:void(document.cookie="UrlWithParameters=" + hsContext.redirectUrl);
       });
   });
});&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Mar 2017 15:21:18 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Include-URL-Parameters-In-Redirect-URL-After-Form-Submission/m-p/240339#M19235</guid>
      <dc:creator>Xfixium</dc:creator>
      <dc:date>2017-03-23T15:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: Include URL Parameters In Redirect URL After Form Submission</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Include-URL-Parameters-In-Redirect-URL-After-Form-Submission/m-p/240340#M19236</link>
      <description>&lt;P&gt;Xfixium,&lt;/P&gt;
&lt;P&gt;I created a forum account just to say thanks… saved me hours.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2017 14:49:49 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Include-URL-Parameters-In-Redirect-URL-After-Form-Submission/m-p/240340#M19236</guid>
      <dc:creator>djpritchett</dc:creator>
      <dc:date>2017-09-05T14:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: Include URL Parameters In Redirect URL After Form Submission</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Include-URL-Parameters-In-Redirect-URL-After-Form-Submission/m-p/240341#M19237</link>
      <description>&lt;P&gt;Thanks Xflxium!! - your solution worked like a champ. (It's a shame HubSpot does allow this functionality by itself.)&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 15:00:23 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Include-URL-Parameters-In-Redirect-URL-After-Form-Submission/m-p/240341#M19237</guid>
      <dc:creator>AlphaDave</dc:creator>
      <dc:date>2018-09-18T15:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: Include URL Parameters In Redirect URL After Form Submission</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Include-URL-Parameters-In-Redirect-URL-After-Form-Submission/m-p/478851#M45939</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/79081"&gt;@Xfixium&lt;/a&gt;&amp;nbsp;Need help passing specific fields from the form as URL query parameters&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Hey,&lt;/P&gt;&lt;P&gt;I found your solution helpful but not sure how to implement it. We want to pass specific fields from the form as URL query parameters. Can you help?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 12:55:51 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Include-URL-Parameters-In-Redirect-URL-After-Form-Submission/m-p/478851#M45939</guid>
      <dc:creator>MdFarhan</dc:creator>
      <dc:date>2021-08-13T12:55:51Z</dc:date>
    </item>
    <item>
      <title>Re: Include URL Parameters In Redirect URL After Form Submission</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Include-URL-Parameters-In-Redirect-URL-After-Form-Submission/m-p/542648#M49480</link>
      <description>&lt;P&gt;For anyone who wants to use the Redirect URL from the form settings:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;window.addEventListener('message', event =&amp;gt; {
    if (event.data.type === 'hsFormCallback' &amp;amp;&amp;amp; event.data.eventName === 'onFormSubmitted') {
      const input = document.querySelector('select[name="input_name"]');
      const context = document.querySelector('input[name="hs_context"]');
      const contextObject = JSON.parse(context.value);
      const redirectUrl = contextObject.redirectUrl; // Retrieve the redirectUrl from the form settings

      if (input) {
        if (input.value &amp;amp;&amp;amp; redirectUrl) {
          window.location.href = redirectUrl + `?input_name=${input.value}`;
        }
      }
    }
  });&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 15 Dec 2021 10:42:23 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Include-URL-Parameters-In-Redirect-URL-After-Form-Submission/m-p/542648#M49480</guid>
      <dc:creator>Teun</dc:creator>
      <dc:date>2021-12-15T10:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: Include URL Parameters In Redirect URL After Form Submission</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Include-URL-Parameters-In-Redirect-URL-After-Form-Submission/m-p/614105#M52397</link>
      <description>&lt;P&gt;Hi Teun,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;not dev here, what does this allow to do exactly?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm looking to add URL parameters (email) to the URL where I redirect users after filling out Hubspot form.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which solution should I go for? Yours,&amp;nbsp;&lt;A href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/2699" target="_self"&gt;&lt;SPAN class=""&gt;lloydsilver&lt;/SPAN&gt;&lt;/A&gt;&amp;nbsp;original post or&amp;nbsp;&lt;SPAN&gt;Xflxium's cookie one&amp;nbsp;&lt;/SPAN&gt;?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And how to implement your solution if that's the preferred one?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 10:07:13 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Include-URL-Parameters-In-Redirect-URL-After-Form-Submission/m-p/614105#M52397</guid>
      <dc:creator>MatthieuBRG</dc:creator>
      <dc:date>2022-04-13T10:07:13Z</dc:date>
    </item>
  </channel>
</rss>

