Multi Step Forms - Possible??

thx @squatchcreative

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

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)

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.

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

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

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!)

@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.

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>

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

I did it by inserting the code directly into the page template, without the form module.

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 ?

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>

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>

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

Yes I have done that

do you have jquery enabled on your pages?

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

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

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!

Do you have a link to this in the marketplace? Did you update the styling of this?

Officially there are several options for this now available in the Marketplace. We have 2 accepted solutions:

MultiFORM Module: This uses multiple forms within a single module, the advantage is you capture data at each step. 2007so太阳集团(中国区)官方网站-Online Platform
Multi-Step Form: This is a single form broken into multiple steps 150 installs in the last year. 2007so太阳集团(中国区)官方网站-Online Platform

NO CODING REQUIRED!