<?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: How to redirect to a page URL based on a form (hidden) field option in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/How-to-redirect-to-a-page-URL-based-on-a-form-hidden-field/m-p/896048#M69848</link>
    <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/179007"&gt;@VRey&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;It seems to me that you have most of the required elements in place for this to work. I'll comment here about how I used the form enhancement mechanics to achieve a content specific redirection. Hopefully there is enough overlap for you to complete your own solution. Since you have got this far, I hope you already know the form MUST be in RAW mode for this type of adaptation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are a couple of things I would comment on specifically:&lt;/P&gt;&lt;P&gt;Firstly, the redirect URL can be added to a form creation directly using one of the parameters: redirectUrl. If timing is an issue here, then the page redirect can be actioned in JS directly on the submit action, although I would note that there seems to be some precedence rules to be applied to the URL thats actually used - that is don't add a redirect value in the form editor directly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Secondly, the extraction of the value from a hidden form field (populated by a query parameter) can actually be undertaken on "form ready" rather than on submit. my own approach may not be optimal, but it is posssible to use the HubSpot generated IDs for this form instance to uncover the DOM Input object and get its value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;      hbspt.forms.create({
        region: "na1",
        portalId: "{{hub_id}}",
        formId: "{{ selected_form_id }}",
          redirectUrl: "{{ module.document_url.href }}",
          onFormReady: function($form) {
            // YOUR SCRIPT HERE
            console.log("ready\n",$form);
            console.log("Salesforce campaign: {{ module.salesforce_campaign }}");
            //find sibling of label on a hidden field)
            var field_id = "label-" + "{{ module.property }}" + "-" + "{{ selected_form_id }}";
            let label = document.getElementById(field_id);
            let field = label.nextSibling.nextSibling.firstChild;
            console.log("Found element type: ", field.nodeName);
          }
      });
 &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Dec 2023 18:41:53 GMT</pubDate>
    <dc:creator>SteveHTM</dc:creator>
    <dc:date>2023-12-19T18:41:53Z</dc:date>
    <item>
      <title>How to redirect to a page URL based on a form (hidden) field option</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-to-redirect-to-a-page-URL-based-on-a-form-hidden-field/m-p/895928#M69844</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've never really used any script and here's my problem:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a HS landing page with a HS form embeded.&lt;/P&gt;&lt;P&gt;If a visitor comes to my landing page from a Wordpress "cloud" page, a hidden property (solution) in the form is filled with "cloud" (with a ? in the url).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So if a visitor comes to the landing page from a "Cloud" page, the hidden form field "solution" is filled with "cloud".&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I need is that when he clicks on "subbmit", he is redirected to a certain url page :&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://mywebsite/cloud_thankyou_page" target="_blank" rel="noopener nofollow noreferrer"&gt;https://mywebsite/cloud_thankyou_page&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and same thing if he comes from the "cyber" page or the "datacenter" page etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this :&amp;nbsp;&lt;/P&gt;&lt;P&gt;(of course the xxx are is stead of the real info)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;lt;script charset="utf-8" type="text/javascript" src="&lt;A href="https://js.hsforms.net/forms/embed/v2.js" target="_blank" rel="noopener nofollow noreferrer"&gt;https://js.hsforms.net/forms/embed/v2.js&lt;/A&gt;"&amp;gt;&amp;lt;/script&amp;gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;lt;script&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;hbspt.forms.create({&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; region: "xxx",&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; portalId: "xxxxxx",&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; formId: "xxxxxxxxxxxxxxxxxxxxxxxxxxx"&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; onFormSubmit: function($form){&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; var solution = $form.find('select[name="solution"]').val();&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;setTimeout( function() {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if (solution == "cloud" ) {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;window.location.href = '&lt;A href="https://mywebsite/cloud_thankyou_page" target="_blank" rel="noopener nofollow noreferrer"&gt;https://mywebsite/cloud_thankyou_page&amp;nbsp;&lt;/A&gt;';}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else if (xprsolution == 'datacenter'){&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; window.location.href = '&lt;A href="https://mywebsite/cloud_thankyou_page" target="_blank" rel="noopener nofollow noreferrer"&gt;https://mywebsite/dc_thankyou_page&amp;nbsp;&lt;/A&gt;';}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else if (xprsolution == 'cyber'){&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; window.location.href = '&lt;A href="https://mywebsite/cloud_thankyou_page" target="_blank" rel="noopener nofollow noreferrer"&gt;https://mywebsite/cyber_thankyou_page&amp;nbsp;&lt;/A&gt;';}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; }, 500 ); //&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; }&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;});&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;lt;/script&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Then I read a post and replaced&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; var solution = $form.find('select[name="solution"]').val();&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;by this line with my info :&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;const employeeCount = $form.querySelector('select[name="numemployees"]').value;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I read about jQuery being desactivated on my pages on HS, so I activaed it. And tried again both versions of the code. Nothing seems to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also I read countless pages on this and nobody explains where we have to put this script ? So I tried in &amp;lt;head&amp;gt; and then in enriched text - advances - source code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Still nothing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could someone please help me ? I've been at this for hours...&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 19 Dec 2023 15:07:31 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-to-redirect-to-a-page-URL-based-on-a-form-hidden-field/m-p/895928#M69844</guid>
      <dc:creator>VRey</dc:creator>
      <dc:date>2023-12-19T15:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to redirect to a page URL based on a form (hidden) field option</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-to-redirect-to-a-page-URL-based-on-a-form-hidden-field/m-p/896048#M69848</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/179007"&gt;@VRey&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;It seems to me that you have most of the required elements in place for this to work. I'll comment here about how I used the form enhancement mechanics to achieve a content specific redirection. Hopefully there is enough overlap for you to complete your own solution. Since you have got this far, I hope you already know the form MUST be in RAW mode for this type of adaptation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are a couple of things I would comment on specifically:&lt;/P&gt;&lt;P&gt;Firstly, the redirect URL can be added to a form creation directly using one of the parameters: redirectUrl. If timing is an issue here, then the page redirect can be actioned in JS directly on the submit action, although I would note that there seems to be some precedence rules to be applied to the URL thats actually used - that is don't add a redirect value in the form editor directly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Secondly, the extraction of the value from a hidden form field (populated by a query parameter) can actually be undertaken on "form ready" rather than on submit. my own approach may not be optimal, but it is posssible to use the HubSpot generated IDs for this form instance to uncover the DOM Input object and get its value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;      hbspt.forms.create({
        region: "na1",
        portalId: "{{hub_id}}",
        formId: "{{ selected_form_id }}",
          redirectUrl: "{{ module.document_url.href }}",
          onFormReady: function($form) {
            // YOUR SCRIPT HERE
            console.log("ready\n",$form);
            console.log("Salesforce campaign: {{ module.salesforce_campaign }}");
            //find sibling of label on a hidden field)
            var field_id = "label-" + "{{ module.property }}" + "-" + "{{ selected_form_id }}";
            let label = document.getElementById(field_id);
            let field = label.nextSibling.nextSibling.firstChild;
            console.log("Found element type: ", field.nodeName);
          }
      });
 &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 18:41:53 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-to-redirect-to-a-page-URL-based-on-a-form-hidden-field/m-p/896048#M69848</guid>
      <dc:creator>SteveHTM</dc:creator>
      <dc:date>2023-12-19T18:41:53Z</dc:date>
    </item>
  </channel>
</rss>

