CMS Development

YJoumaa
Member

Embed form with additional Function

I tried to embed this form in a new template but it is not showing up!

 

I'm pretty sure I used the right syntax for the function

 

 

 

 

 

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
hbspt.forms.create({
region: "na1",
portalId: "3221062",
formId: "1e1d64cd-9d70-4edf-a9f7-36d26a086059",
inlineMessage: 'You are being redirected to your sign in page...',
onFormSubmit: function($form){

var companyName = $form.find('input[company="FieldID"]').val();
setTimeout( function() {
window.location.href = "https://" + encodeURIComponent( companyName ) + "rhonda.ai/accounts/login";
}, 500 ); // Redirects to url with query string data from form fields after 1/2 second.

}
});
</script>

0 Upvotes
2 Replies 2
Indra
Guide | Elite Partner
Guide | Elite Partner

Embed form with additional Function

Hi @YJoumaa,

 

I think your variable is incorrect and should be:

var companyName = $form.find('input[name="company"]').val();

 

So your complete could shoud be:

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
  hbspt.forms.create({
    region: "na1",
    portalId: "3221062",
    formId: "1e1d64cd-9d70-4edf-a9f7-36d26a086059",
    inlineMessage: 'You are being redirected to your sign in page...',
    onFormSubmit: function($form){

      var companyName = $form.find('input[name="company"]').val();
      console.log('tesdt' + companyName);
      setTimeout( function() {
        window.location.href = "https://" + encodeURIComponent( companyName ) + "rhonda.ai/accounts/login";
      }, 500 ); // Redirects to url with query string data from form fields after 1/2 second.

    }
  });
</script>

 

Perhaps the windows.location.href sould also be changed since if I will fill in the company 'HubSpot' my returning value will be: https://HubSpotrhonda.ai/accounts/login . Do you want it to be a subdomain? Than you should change the JS and add a . (dot) so you code will be:

window.location.href = "https://" + encodeURIComponent( companyName ) + ".rhonda.ai/accounts/login";

 


Vet Digital - The Growth Agency | HubSpot Solutions Partner Agency

Did my post solve your question? Help the community by marking it as a solution
Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

Embed form with additional Function

Hey @YJoumaa 

 

Are you getting any errors in the console? And could you link us to the page so we can dig a little deeper?

Kevin Cornett - Sr. Solutions Architect @ BridgeRev