Skip to content

Instantly share code, notes, and snippets.

@thesnappingdog
Last active April 25, 2022 19:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thesnappingdog/44e470c160e13d3208ad5cf613027a47 to your computer and use it in GitHub Desktop.
Save thesnappingdog/44e470c160e13d3208ad5cf613027a47 to your computer and use it in GitHub Desktop.
Two-Step form in HubSpot
<h1>2 Step Form</h1>
<div id="demo-form"></div>
<script charset="utf-8" type="text/javascript" src="https://js.hsforms.net/forms/v2.js"></script>
<script>
var data = []
hbspt.forms.create({
portalId: "YOUR_PORTAL_ID_HERE",
formId: "STEP_ONE_FORM_ID_HERE",
target: "#demo-form",
onFormSubmit: function(form) {
var incoming = $(form).serializeArray();
data.push(incoming);
},
onFormSubmitted: function(form) {
$('#demo-form').empty();
hbspt.forms.create({
portalId: "YOUR_PORTAL_ID_HERE",
formId: "STEP_TWO_FORM_ID_HERE",
target: "#demo-form",
onFormReady: function(form) {
form.find('input[name="email"]').val(data[0].value).change();
}
})
}
});
</script>
@golchha21
Copy link

This is not working.
This ends up showing the message.

@thesnappingdog
Copy link
Author

Can you elaborate a bit more? Not sure where to start debugging. also there are some conditions on hubspots side to get this working.

  • email field needs to be first on both forms
  • 'render as raw html' needs to be enabled
  • jquery loaded

i also made a generator for these, maybe this one works for you: https://github.com/thesnappingdog/hubspot-multistep-form-generator

@golchha21
Copy link

I happened to use the above code only and missed out on jQuery, that is the reason why it didn't work.

@thesnappingdog
Copy link
Author

Super! Happy to hear

@Temona007
Copy link

Hello Richard,

how can i add a 3-steps form?

Thanks in advance

@thesnappingdog
Copy link
Author

Hi @Temona007 try using the generator i built -- it should allow you to make infinite step forms: https://github.com/thesnappingdog/hubspot-multistep-form-generator

@Temona007
Copy link

Hi @Temona007 try using the generator i built -- it should allow you to make infinite step forms: https://github.com/thesnappingdog/hubspot-multistep-form-generator

Great thanks and have a sunny day!

@Sakshibansal1995
Copy link

Sakshibansal1995 commented Apr 3, 2021

Hi, how can we add a progress bar in this multi step form?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment