APIs & Integrations

Nikboe
Participant

Form onSubmit send to auto generated URL with form input

SOLVE

Hi! We are trying to build a from with the following functionality in pseudocode:

 

onSubmit --> save data in hubspot --> get input from company form field --> send to URL "example.com/affiliate?=companyname"

 

Should be simple, right? But I am already struggeling with the onSubmit function, nothing happens:

 

<!--[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: "48...51",
	formId: "30...cf74b3",
    onFormSubmit: function($form){
      alert("test");
    }
});
</script>

 I created this as a custome module, the form gets displayed, but the alert doesnt pop up.

 

 

I would really appreciate help! Thanks!

0 Upvotes
1 Accepted solution
Nikboe
Solution
Participant

Form onSubmit send to auto generated URL with form input

SOLVE

Solved it!

 

Found the solution here: https://community.hubspot.com/t5/APIs-Integrations/Include-form-fields-as-redirect-URL-parameters-on...

 

My final code:

<!--[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: "4.....51",
	    formId: "30a3b64e-a...f2cf74b3",
      inlineMessage: 'Your submit message here',
      onFormSubmit: function($form){
          setTimeout( function() {
            var affiliateID = $form.find('input[name="company"]').val();
            window.location = "https://www.yournicepage.com/?affiliate=" + encodeURIComponent( affiliateID );
          }, 250 ); // Redirects to url with query string data from form fields after 250 milliseconds.
      }
});
 </script>

View solution in original post

1 Reply 1
Nikboe
Solution
Participant

Form onSubmit send to auto generated URL with form input

SOLVE

Solved it!

 

Found the solution here: https://community.hubspot.com/t5/APIs-Integrations/Include-form-fields-as-redirect-URL-parameters-on...

 

My final code:

<!--[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: "4.....51",
	    formId: "30a3b64e-a...f2cf74b3",
      inlineMessage: 'Your submit message here',
      onFormSubmit: function($form){
          setTimeout( function() {
            var affiliateID = $form.find('input[name="company"]').val();
            window.location = "https://www.yournicepage.com/?affiliate=" + encodeURIComponent( affiliateID );
          }, 250 ); // Redirects to url with query string data from form fields after 250 milliseconds.
      }
});
 </script>