Lists, Lead Scoring & Workflows

Jonnydk
Top Contributor

Multi Step Forms - Possible??

SOLVE

Hi is it possible to achieve a "multi-step" form through hubspot. The first part of the form would be the basics, First Name, Last Name, Work Email and Company Name. Once the user clicks "Next" we would ask them to fill in more details. If they leave before or after next we will capture their info and assign them to a lifecycle stage and if they finish the next step we will qualify them for a sales call. Is this possible, if so how can I achieve this? TYIA Heart

1 Accepted solution
thesnappingdog
Solution
Contributor

Multi Step Forms - Possible??

SOLVE

hey I don't know if anyone's still looking for a solution to this. 

 

I wrote a how to + shared the code for creating 2 step forms.

 

However with this method you can chain any amount of forms if you want, it's just nicer to split the code into neat functions rather than what is done in the how-to.

 

hopefully this helps someone!

 

how-to:

 https://hyper-typed-marketing.mailchimpsites.com/growth-multistep-forms-hubspot

code: https://gist.github.com/thesnappingdog/44e470c160e13d3208ad5cf613027a47

 

P.S. this works without hiccups except that... completing two step form counts as.. two form submissions 😄 

 

Edit: I made a multi step generator so nobody has to painfully copy paste code. see other reply for more details: 

 

https://github.com/thesnappingdog/hubspot-multistep-form-generator

View solution in original post

72 Replies 72
Sandeld
Participant

Multi Step Forms - Possible??

SOLVE

Hey, this worked for me, thanks!

I'm kind of a developer, but not really. (lol) So I'm wondering, how much do I have to worry about the data array index changing in the future? I know it's out of our control and Hubspot isn't going to send out a user-wide email, but if this custom code ever stops working, it might be difficult to catch.

Also, if someone quits halfway through the forms, I know we can send them a reminder email to come back and fill it out using the HS automations, but is there a way to send them to the exact step on the original page? Otherwise, the workaround is to create individual pages corresponding to individual steps. Then updating the embed code to only include the forms from that point forward.

 

Thank you!

 

 

0 Upvotes
sboi
Participant

Multi Step Forms - Possible??

SOLVE

How can i get to this HTML interface in hubspot ,do i have to create a form Module and write this code?

0 Upvotes
elanashama
Top Contributor

Multi Step Forms - Possible??

SOLVE
I did it by inserting the code directly into the page template, without the form module.
0 Upvotes
sboi
Participant

Multi Step Forms - Possible??

SOLVE

 thank you, i managed to create a page and embded the script with in the body,however it doesnt flow on to the next form, it is stuck on form one only.

any reason ?

 

0 Upvotes
elanashama
Top Contributor

Multi Step Forms - Possible??

SOLVE

Is this the code you embedded?

 

<div id="demo-form"></div>

    <script>

      var data = []

      hbspt.forms.create({

      portalId: "INSERT_PORTAL_ID",

      formId: "INSERT_FORM_ID",

      target: "#demo-form",

      onFormSubmit: function(form) {

      var incoming = $(form).serializeArray();

      data.push(incoming);

      },

          onFormSubmitted: function(form) {

          $('#demo-form').empty();

          hbspt.forms.create({

          portalId: " INSERT_PORTAL_ID ",

          formId: " INSERT_FORM_ID ",

          target: "#demo-form",

          onFormReady: function(form) {

          form.find('input[name="email"]').val(data[0].value).change();

          }

          })

          }

      });

     </script>

0 Upvotes
sboi
Participant

Multi Step Forms - Possible??

SOLVE

here is the html code of the page , which has the above in it.

<!--
  templateType: "page"
  isAvailableForNewContent: true
-->
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="{{ html_lang }}" {{ html_lang_dir }}> <![endif]-->
<!--[if IE 7]>    <html class="no-js lt-ie9 lt-ie8" lang="{{ html_lang }}" {{ html_lang_dir }}>        <![endif]-->
<!--[if IE 8]>    <html class="no-js lt-ie9" lang="{{ html_lang }}" {{ html_lang_dir }}>               <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="{{ html_lang }}" {{ html_lang_dir }}> <!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="author" content="{{ meta_author }}">
    <meta name="description" content="{{ page_meta.meta_description }}">
    <meta name="generator" content="HubSpot">
    {% if page_meta.html_title %}<title>{{ page_meta.html_title }}</title>{% endif %}
    {% if site_settings.favicon_src %}<link rel="shortcut icon" href="{{ site_settings.favicon_src }}" />{% endif %}
    
{{ required_head_tags }}
    
    {{ include_css("/hubspot_default/shared/responsive/layout.css") }}
    {{ user_head_overrides }}

</head>
<body class=" {{ builtin_body_classes }}" style="">
    <div class="header-container-wrapper">
    <div class="header-container container-fluid">


    </div><!--end header -->
</div><!--end header wrapper -->

<div class="body-container-wrapper">
    <div class="body-container container-fluid">


    </div><!--end body -->
</div><!--end body wrapper -->
<div id="demo-form"></div>
    <script>
      var data = []
      hbspt.forms.create({
      portalId: "INSERT_PORTAL_ID ",
      formId: "INSERT_FORM_ID",
      target: "#demo-form",
      onFormSubmit: function(form) {
      var incoming = $(form).serializeArray();
      data.push(incoming);
      },
          onFormSubmitted: function(form) {
          $('#demo-form').empty();
          hbspt.forms.create({
          portalId: "INSERT_PORTAL_ID  ",
          formId: "INSERT_FORM_ID ",
          target: "#demo-form",
          onFormReady: function(form) {
          form.find('input[name="email"]').val(data[0].value).change();
          } 
          })
          }
      });
     </script>
<div class="footer-container-wrapper">
    <div class="footer-container container-fluid">


    </div><!--end footer -->
</div><!--end footer wrapper -->

    {{ standard_footer_includes }}
    
    <!-- Generated by the HubSpot Template Builder - template version 1.03 -->
</body>
</html>
0 Upvotes
elanashama
Top Contributor

Multi Step Forms - Possible??

SOLVE
You need to insert your hubspot account portal ID and the relevant form IDs. Have you done that?

0 Upvotes
sboi
Participant

Multi Step Forms - Possible??

SOLVE
Yes I have done that
0 Upvotes
elanashama
Top Contributor

Multi Step Forms - Possible??

SOLVE

do you have jquery enabled on your pages? 

0 Upvotes
sboi
Participant

Multi Step Forms - Possible??

SOLVE

I have enabled jQuery now , however i now get complete blank page in preview

0 Upvotes
elanashama
Top Contributor

Multi Step Forms - Possible??

SOLVE
This is the extent of my knowledge in this area. Sorry I can’t be of more help.
SimonKay
Member

Multi Step Forms - Possible??

SOLVE

Thanks for this - I'm running your code above (and have elongated it to 5 forms) and it's showing them sequentially front end (on my Wordpress site). However the data is only being captured in HubSpot for the first form submission – it's as though it's not linking the other 4 forms that follow to the Contact record.

I've replaced the $ (dollar sign) with "jQuery" as suggested by @thesnappingdog in his original article and have played aorund with both the original array level and your suggested depper array @squatchcreative.

 

Is there anything else I should look at to ensure that the email is being handed off correctly between forms?

(Evidentally, I'm not a JS pro, so appreciate the help!)

0 Upvotes
squatchcreative
Contributor

Multi Step Forms - Possible??

SOLVE

@SimonKay  It's impossible to troubleshoot your issue without seeing your code.  Were you having success with it working as 2 steps before you turned it into 5 steps? I would start there before you added to the complexity of the form.  Begin with two forms, use @thesnappingdog example, and see if that works.   Find out if it is handing off the email to the next form with just 2. If it doesn't, post that code, and any errors in your console when it doesn't work.  If it does work, try 3, and so on.  

 

My example and his example traverse down a Javascript array differently, so which one are you using?  Did you try the other?  Try outputting the email variable to your console log -- see what it says.  Is it blank?  Does it output the email correctly?  When you go to the 2nd step, inspect your email field.... did it place the email value in there for you?  You need to check all of these things to make sure you are actually passing the email variable.

 

Good luck. 

SimonKay
Member

Multi Step Forms - Possible??

SOLVE

I appreciate that, thanks @squatchcreative. Code below this.

I tried scaling from 2, to 3,4,5 forms. On all fronts, the form progressed through the sequence (i.e. on submit, I was able to see and complete the next form), however HubSpot is only recording the data submitted from the FIRST form. As though it's not attributing the following forms with that Contact – and therefore isn't passing the email variable.

I tried with both array options. I also altered the JS script link (as mentioned in the thread) and played with switching the "$" vs. "jQuery" variables (you'll see I landed on the latter in my code below, since this actually allowed the forms to appear one after another).

So it would appear the issue is the email hand-off.

 

Thanks for your help – much appreciated.

 

 

<div id="form-container"></div>
<script charset="utf-8" type="text/javascript" src="https://js.hsforms.net/forms/v2.js"></script>
<script>
	var data = [];

	hbspt.forms.create({
		portalId: "XXXX",
		formId: "XXXX",
		target: "#form-container",
		onFormSubmit: function(form) {
			var incoming = jQuery(form).serializeArray();
			data.push(incoming);
		},
		onFormSubmitted: function(form) {
			jQuery('#form-container').empty();
			hbspt.forms.create({
				portalId: "XXXX",
				formId: "XXXX",
				target: "#form-container",
				onFormReady: function(form) {
					form.find('input[name="email"]').val(data[0].value).change();
				},
				onFormSubmitted: function(form) {
					jQuery('#form-container').empty();
					hbspt.forms.create({
						portalId: "XXXX",
						formId: "XXXX",
						target: "#form-container",
						onFormReady: function(form) {
							form.find('input[name="email"]').val(data[0].value).change();
						},
						onFormSubmitted: function(form) {
							jQuery('#form-container').empty();
							hbspt.forms.create({
								portalId: "XXXX",
								formId: "XXXX",
								target: "#form-container",
								onFormReady: function(form) {
									form.find('input[name="email"]').val(data[0].value).change();
								},
								onFormSubmitted: function(form) {
									jQuery('#form-container').empty();
									hbspt.forms.create({
										portalId: "XXXX",
										formId: "XXXX",
										target: "#form-container",
										onFormReady: function(form) {
											form.find('input[name="email"]').val(data[0].value).change();
										}
									})
								}
							})
						}
					})
				}
			})
		}
	});
</script>

 

thesnappingdog
Contributor

Multi Step Forms - Possible??

SOLVE

I remember running into this problem as well when building the proto:

 

var incoming = $(form).serializeArray();
data.push(incoming);
form.find('input[name="email"]').val(data[0][0].value).change();

 

I think it started happening if i $(form).serializeArray multiple times, then the data var ended up having other arrays in it :S 

0 Upvotes
thesnappingdog
Contributor

Multi Step Forms - Possible??

SOLVE

that's awesome @squatchcreative @rwolupo ! I was thinking about this yesterday, and specifically how @squatchcreative you probably had to do a lot of copypasting with a 6 step form.. I'm gonna try to make a multi-step generator so that you guys only need to edit a formId array, target and portal id. 

 

At the end of the day hbspt.forms.create() just needs an object with info and it should be possible to make that programmatic (first step options, inbetween, last form options)

thesnappingdog
Contributor

Multi Step Forms - Possible??

SOLVE

hey @Jonnydk @rwolupo @squatchcreative @elanashama can I ask you to be pilots for something.

 

Long story short, I made a generator that does all the work you'd have to do with my previous code. It will create as many steps as you have forms.

 

Now you just need to edit:

 

- forms = [form1, form2, etc]

- target = 'container id'

- portalId = 'your portal id'

 

It worked flawlessly for me on a Chrome browser, each steps' submission was recorded in the CRM. I tried with 3 forms, then with 4. It's written in more modern javascript so if this works well I could see what the code would be in old timey script.

 

https://github.com/thesnappingdog/hubspot-multistep-form-generator

 

Please see the README.md before implementing and please let me know if there's bugs / errors either here or on github 🙏

rwolupo
Top Contributor

Multi Step Forms - Possible??

SOLVE

thx @squatchcreative 

it worked for me - except of the form.find thing ... i had to use the orginal code from @thesnappingdog 

thesnappingdog
Solution
Contributor

Multi Step Forms - Possible??

SOLVE

hey I don't know if anyone's still looking for a solution to this. 

 

I wrote a how to + shared the code for creating 2 step forms.

 

However with this method you can chain any amount of forms if you want, it's just nicer to split the code into neat functions rather than what is done in the how-to.

 

hopefully this helps someone!

 

how-to:

 https://hyper-typed-marketing.mailchimpsites.com/growth-multistep-forms-hubspot

code: https://gist.github.com/thesnappingdog/44e470c160e13d3208ad5cf613027a47

 

P.S. this works without hiccups except that... completing two step form counts as.. two form submissions 😄 

 

Edit: I made a multi step generator so nobody has to painfully copy paste code. see other reply for more details: 

 

https://github.com/thesnappingdog/hubspot-multistep-form-generator

sboi
Participant

Multi Step Forms - Possible??

SOLVE

Hi ,can you help on this i have tried mutipage form as below ,however it is not loading at all.

<!--
    templateType: page
    isAvailableForNewContent: true
-->
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">

   
    {{ standard_header_includes }}
  </head>
  <body>
    {% dnd_area "dnd_area"
      label="Main section"
    %}
      {% dnd_section %}
        {% dnd_column %}
          {% dnd_row %}

            {% dnd_module path="@hubspot/logo" %}
            {% end_dnd_module %}

          {% end_dnd_row %}
          {% dnd_row %}

            {% dnd_module path="@hubspot/rich_text" %}
            {% end_dnd_module %}

          {% end_dnd_row %}
        {% end_dnd_column %}
      {% end_dnd_section %}
    {% end_dnd_area %}
    {{ standard_footer_includes }}
    
    <div id="demo-form"></div>
    <script>
      var data = []
      hbspt.forms.create({
      portalId: "XXXXXX",
      formId: "XXXXXX",
      target: "#demo-form",
      onFormSubmit: function(form) {
      var incoming = $(form).serializeArray();
      data.push(incoming);
      },
          onFormSubmitted: function(form) {
          $('#demo-form').empty();
          hbspt.forms.create({
          portalId: "XXXXXX",
          formId: "XXXXXXX",
          target: "#demo-form",
          onFormReady: function(form) {
          form.find('input[name="email"]').val(data[0].value).change();
          } 
          })
          }
      });
     </script>
  </body>
</html>
0 Upvotes
elanashama
Top Contributor

Multi Step Forms - Possible??

SOLVE

Hi @thesnappingdog ,

 

Is there a way to add a "previous" button to the second form, so that someone can go back to the first form? Also, when doing so, would the user lose all data inserted into the second form? 

0 Upvotes