Hi,
I need to build a module that asks a series of questions on clicking next such as how many baths, showers, people in the house and then computes the amount of water saved at the end to display. How can I achieve this ?? Can someone guide me.
Hi,
I need to build a module that asks a series of questions on clicking next such as how many baths, showers, people in the house and then computes the amount of water saved at the end to display. How can I achieve this ?? Can someone guide me.
Hi @aparnarevi, I’ve achieved this, but it’s quite difficult.
I coded the multi-step form myself in HTML with all the steps, created a new Hubspot form for each step and used the Forms API to send the input data to Hubspot when “Next” was clicked. You could send the data to one Hubspot form via the API after all the steps are done, but I wanted to capture the info at each stage in case anyone dropped off. I originally had a second multi-step form after the first so that the user could give additional info if they wanted. I’ve removed that from the below to make it a bit shorter, but that’s why you might see form1 and form2.
Here’s my HTML:
<div class="form-wrapper">
<h1>{{module.title}}</h1>
<!-- multistep form 1 -->
<form class="msform" id="form1">
<!-- progressbar1 -->
<ul class="progressbar" id="progressbar1">
<li class="active"></li>
<li></li>
<li></li>
</ul>
<!-- fieldsets -->
<fieldset class="form1-fieldset" id="step1">
<h2 class="fs-title">Tell us a bit about you</h2>
<label for="firstname">First name<span class="required">*</span></label>
<input type="text" name="firstname" placeholder=""/>
<label for="lastname">Last name<span class="required">*</span></label>
<input type="text" name="lastname" placeholder=""/>
<label for="email">Your work email<span class="required">*</span></label>
<input type="text" name="email" id="email1" placeholder=""/>
<div class="checkbox">
<input type="checkbox" id="newsletter" class="regular-checkbox" name="newsletter">
<label for="newsletter">Send me insightful updates about industry innovation, and invites to wholesome Mews events!</label>
</div>
<a type="button" name="next" class="button button--black full-btn next step1 mb-20" value="Next" data-clicked>Next</a>
<small>By clicking Next you agree to allow Mews Systems to periodically send relevant information, and use your data in accordance with our <a href="/privacy">privacy policy</a>. You can unsubscribe or update your preferences at any time.</small>
</fieldset>
<fieldset class="form1-fieldset">
<h2 class="fs-title">Tell us a bit about your company</h2>
<label for="property_name">Property name<span class="required">*</span></label>
<input type="text" name="property_name" placeholder=""/>
<p class="text-left">Property type<span class="required">*</span></p>
<div class="radio-wrapper mb-40">
<div class="radio-container">
<div class="radio">
<input type="radio" id="hotel" name="property_type_multi" value="hotel">
<label for="hotel">Hotel</label>
</div>
<div class="radio">
<input type="radio" id="propertygroup" name="property_type_multi" value="property_group">
<label for="propertygroup">Group of properties</label>
</div>
</div>
<div class="radio-container">
<div class="radio">
<input type="radio" id="hostel" name="property_type_multi" value="hostel">
<label for="hostel">Hostel</label>
</div>
<div class="radio">
<input type="radio" id="apartment" name="property_type_multi" value="apartment">
<label for="apartment">Apartment</label>
</div>
</div>
<div class="radio-container">
<div class="radio">
<input type="radio" id="other-radio" name="property_type_multi" value="other">
<label for="other-radio">Other</label>
</div>
</div>
</div>
<div id="other">
<label for="property_type_other_">Other</label>
<input type="text" name="property_type_other_" placeholder=""/>
</div>
<div id="propgroup">
<label for="property_type_group">Name of group</label>
<input type="text" name="property_type_group" placeholder=""/>
</div>
<label for="property_size_multi_step_demo_form_">Property size <span id="propSize">(# of rooms)</span><span class="required">*</span></label>
<select name="property_size_multi_step_demo_form_">
<option value="" disabled="" selected=""> Please select</option>
<option value="<30" >1 - 30 rooms</option>
<option value="31-100" >31 - 100 rooms</option>
<option value=">100" >Over 100 rooms</option>
</select>
<label for="country">Country<span class="required">*</span></label>
<div class="country">
<select name="country1" id="country">
<option value disabled selected>Please select</option>
<option value="Afghanistan">Afghanistan</option>
<option value="Åland Island">Åland Island</option>
<--! list of countries -->
</select>
</div>
<div class="location-wrapper">
<a href="#" id="locationGet"><span><img src="https://www.mews.com/hubfs/august_theme_assets/distributor/icons/location-icon.svg">Get my location</span></a>
</div>
<input type="text" name="email" class="email-hide" placeholder=""/>
<a type="button" name="previous" class="button button--transparent previous" value="Previous">Previous</a>
<a type="button" name="next" class="button button--black next step2" value="Next" data-clicked>Next</a>
</fieldset>
<fieldset class="form1-fieldset">
<h2 class="fs-title"><span id="fName">H</span>ow would you like us to get in touch?</h2>
<div class="radio-wrapper mb-40">
<div class="radio-container">
<div class="radio">
<input type="radio" id="contact_email" name="contact_type_preference" value="email">
<label for="contact_email">Email</label>
</div>
<div class="radio">
<input type="radio" id="contact_phone" name="contact_type_preference" value="phone">
<label for="contact_phone">Phone</label>
</div>
</div>
</div>
<div id="phone">
<label for="phone">Phone number</label>
<input type="text" name="phone" placeholder=""/>
</div>
<input type="text" name="email" class="email-hide" placeholder=""/>
<a type="button" name="previous" class="button button--transparent previous" value="Previous">Previous</a>
<a type="submit" name="submit" class="button btn-text-black submit" id="submit1" value="Submit">Submit</a>
</fieldset>
<fieldset>
<h2 class="fs-title">Thanks!</h2>
<p class="text-left">A Mews expert will get in touch with you shortly.</p>
<div class="flex-container flex-dir-column">
<a type="button" class="button button--black" href="/customer-stories">See what our customers say about us</a>
<a type="button" class="button button--black" href="/">Back to homepage</a>
</div>
</fieldset>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.19.1/dist/jquery.validate.min.js" type="text/javascript"></script>
jQuery:
var current_fs, next_fs, previous_fs; //fieldsets
var left, opacity, scale; //fieldset properties which we will animate
var animating; //flag to prevent quick multi-click glitches
$(document).ready(function() {
$('#form1').validate({
rules: {
email: {
required: true,
email: true
},
firstname: "required",
lastname: "required",
property_name: "required",
property_type_multi: "required",
property_size_new: {
required: true,
number: true
},
country1: "required",
contact_type_preference: "required",
phone: {
number: true,
required: {
depends: function(e) {
if ($('input#contact_phone').is(':checked')) {
return true;
} else {
return false;
}
}
}
},
},
messages: {
email: "Please provide a valid email address",
firstname: "This field is required",
lastname: "This field is required"
}
});
});
$('.next, .submit').click(function(){
$('#form1').valid();
if ((!$('#form1').valid())) {
return false;
}
var stepInputs = $(this).closest('fieldset').find('input, select');
var serialFieldset = (fieldset) => {
var r = fieldset.serializeArray();
return r;
};
var output = serialFieldset(stepInputs);
const getCookie = (name) => {
return document.cookie.split('; ').reduce((r, v) => {
const parts = v.split('=')
return parts[0] === name ? decodeURIComponent(parts[1]) : r
}, '')
};
var hubCookie = getCookie('hubspotutk');
var pageURL = window.location.href;
var pageName = $('title')[0].innerHTML;
var timestamp = Date.now();
var email = $('#email1').val();
var comms = false;
var commsText = 'I do not consent to communicate text for subscription type ID 7271920';
var commsTextTwo = 'I do not consent to communicate text for subscription type ID 7214257';
if ($('input#newsletter').prop('checked')) {
comms = true;
commsText = 'Consent to communicate text for subscription type ID 7271920';
commsTextTwo = 'Consent to communicate text for subscription type ID 7214257';
}
var data = {
"submittedAt": timestamp,
"fields": output,
"context": {
"pageUri": pageURL,
"pageName": pageName
},
"legalConsentOptions": {
"consent": {
"consentToProcess": true,
"text": "I agree to allow Mews to store and process my personal data.",
"communications": [{
"value": comms,
"subscriptionTypeId": 7271920,
"text": commsText
},
{
"value": comms,
"subscriptionTypeId": 7214257,
"text": commsTextTwo
}]
}
},
"skipValidation": true
};
var params = {
url: '',
type: "POST",
contentType: "application/json",
dataType: "json",
headers: {
"accept": "application/json",
"Access-Control-Allow-Origin":"*"
},
type: "POST",
data: JSON.stringify(data),
// success: function (result) {
// console.log(result);
// },
error: function (status, error) {
console.log(error, status);
}
};
if ($(this).is('.step1')) {
params.url = 'https://api.hsforms.com/submissions/v3/integration/submit/[PORTAL ID]/[FORM ID]';
$('.email-hide').val(email);
var getFirstName = $('input:text[name="firstname"]').val();
$('#fName').text(getFirstName+', h');
} else if ($(this).is('.step2')) {
params.url = 'https://api.hsforms.com/submissions/v3/integration/submit/[PORTAL ID]/[FORM ID]';
} else if ($(this).is('#submit1')) {
params.url = 'https://api.hsforms.com/submissions/v3/integration/submit/[PORTAL ID]/[FORM ID]';
}
$.ajax(params);
if(animating) return false;
animating = true;
$(this).data('clicked', 'true');
current_fs = $(this).parent();
next_fs = $(this).parent().next();
//activate next step on progressbar using the index of next_fs
$('#progressbar1 li').eq($('.form1-fieldset').index(next_fs)).addClass('active');
//show the next fieldset
next_fs.show();
//hide the current fieldset with style
current_fs.animate({opacity: 0}, {
step: function(now, mx) {
//as the opacity of current_fs reduces to 0 - stored in "now"
//1. scale current_fs down to 80%
scale = 1 - (1 - now) * 0.2;
//2. bring next_fs from the right(50%)
left = (now * 50)+"%";
//3. increase opacity of next_fs to 1 as it moves in
opacity = 1 - now;
current_fs.css({
'transform': 'scale('+scale+')',
'position': 'absolute'
});
next_fs.css({'left': left, 'opacity': opacity});
},
duration: 600,
complete: function(){
current_fs.hide();
animating = false;
},
//this comes from the custom easing plugin
easing: 'easeInOutBack'
});
});
$(".previous").click(function(){
if(animating) return false;
animating = true;
current_fs = $(this).parent();
previous_fs = $(this).parent().prev();
//de-activate current step on progressbar
$('#progressbar1 li').eq($('.form1-fieldset').index(next_fs)).removeClass('active');
//show the previous fieldset
previous_fs.show();
//hide the current fieldset with style
current_fs.animate({opacity: 0}, {
step: function(now, mx) {
//as the opacity of current_fs reduces to 0 - stored in "now"
//1. scale previous_fs from 80% to 100%
scale = 0.8 + (1 - now) * 0.2;
//2. take current_fs to the right(50%) - from 0%
left = ((1-now) * 50)+"%";
//3. increase opacity of previous_fs to 1 as it moves in
opacity = 1 - now;
current_fs.css({'left': left});
previous_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity});
},
duration: 600,
complete: function(){
current_fs.hide();
animating = false;
},
//this comes from the custom easing plugin
easing: 'easeInOutBack'
});
});
// json to send to geo location to look up country associated with ip
var location = {
"async": true,
"crossDomain": true,
"url": "",
"method": "GET",
"headers": {
"x-rapidapi-host": "ip-geo-location.p.rapidapi.com",
"x-rapidapi-key": "[RAPID API KEY]"
}
}
//linking ajax calls together, first one to get user ip address
function firstAjax() {
return $.ajax({
dataType: "json",
url: 'http://jsonip.com/?callback=?',
data: '',
success: function(obj){
var ip = obj.ip
location.url = "https://ip-geo-location.p.rapidapi.com/ip/"+ip+"?format=json"
}
});
}
// second ajax call to look up country name of ip address and change value of country dropdown to user's country
function secondAjax() {
return $.ajax(location).done(function (response) {
var country = response.country.name;
$("select[name='country1'").val(country);
});
}
$('#locationGet').click(function(e) {
e.preventDefault();
var btn = $(this);
btn.prop('disabled',true);
btn.css({
'opacity' : '0.3',
'pointer-events' : 'none',
});
window.setTimeout(function(){
btn.prop('disabled',false);
btn.css({
'opacity' : '1',
'pointer-events' : 'auto',
});
},1000);
// do the actual ajax calls on click
firstAjax().success(secondAjax);
});
$('#submit1').click(function() {
if ($('#form1').valid()) {
$('#progressbar1').addClass('fade');
}
});
I exceeded the character limit on messages so have to add CSS here:
/*form styles*/
.msform {
max-width: 700px;
margin: 0px auto;
text-align: center;
position: relative;
}
.msform fieldset {
background: white;
border: 0 none;
border-radius: 3px;
/* box-shadow: 0 0 15px 1px rgba(0, 0, 0, 0.4); */
padding: 30px;
box-sizing: border-box;
width: 80%;
margin: 0 10%;
/*stacking fieldsets above each other*/
position: relative;
}
/*Hide all except first fieldset*/
.msform fieldset:not(:first-of-type) {
display: none;
}
/* labels */
.msform label {
text-align: left;
margin-right: 0px;
}
.required {
color: red;
margin-left: 5px;
}
label.error {
font-size: 10px;
margin-top: -35px;
margin-bottom: 22px;
color: red;
}
/*inputs*/
.msform input, .msform textarea {
border: none;
border-bottom: 1px solid #000;
padding-bottom: 8px;
padding-left: 0;
margin-bottom: 40px;
max-height: 300px;
font-size: 14px;
line-height: 16px;
font-weight: 400;
}
.msform input:focus, .msform textarea:focus {
border: none;
border-bottom: 1px solid #fecb2e;
font-weight: 700
}
.checkbox {
width: 100%;
display: flex;
margin-top: -20px;
margin-bottom: 20px;
padding-left: 20px;
}
.checkbox input[type="checkbox"] {
opacity: 0;
}
.checkbox label {
font-size: 12px;
position: relative;
display: inline-block;
margin-left: -17px;
/*16px width of fake checkbox + 6px distance between fake checkbox and text*/
padding-left: 22px;
}
.checkbox label::before,
.checkbox label::after {
position: absolute;
content: "";
/*Needed for the line-height to take effect*/
display: inline-block;
}
/*Outer box of the fake checkbox*/
.checkbox label::before{
height: 16px;
width: 16px;
border: 1px solid;
left: 0px;
/*(24px line-height - 16px height of fake checkbox) / 2 - 1px for the border
*to vertically center it.
*/
top: 3px;
}
/*Hide the checkmark by default*/
.checkbox input[type="checkbox"] + label::after {
content: none;
}
/*Unhide on the checked state*/
.checkbox input[type="checkbox"]:checked + label::after {
content: "";
}
/*Adding focus styles on the outer-box of the fake checkbox*/
.checkbox input[type="checkbox"]:focus + label::before {
outline: rgb(59, 153, 252) auto 5px;
}
/* new */
.regular-checkbox {
display: none;
}
.regular-checkbox + label {
display: inline-block;
position: relative;
}
/* style the checkmark */
.regular-checkbox:checked + label:after {
position: absolute;
top: 3px;
left: 0px;
color: #fff;
height: 16px;
background-color: #000;
background-image: url(https://cdn2.hubspot.net/hubfs/5255565/august_theme_assets/front/white-tick.svg);
background-size: cover;
width: 16px;
}
.radio-wrapper {
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
position: relative;
}
.radio-container {
display: flex;
justify-content: space-between;
justify-content: flex-start;
width: 71%;
}
.radio {
width: 100%;
display: flex;
margin-top: 10px;
}
.radio-container label, .radio-wrapper label {
margin-left: .5rem;
}
.msform input[type=checkbox], .msform input[type=radio] {
margin-bottom: 0px;
width: 20px;
margin-top: 4px;
}
.msform input[type=radio] {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
border-radius: 50%;
height: 20px;
border: 1px solid #000;
transition: 0.1s all linear;
margin-right: 5px;
position: relative;
top: -3px;
}
#form2 .radio-wrapper .radio {
width: 100%;
}
.msform input[type=radio]:checked {
border-width: 6px;
}
select {
border: 0;
border-bottom: 1px solid #000;
padding-bottom: 8px;
padding-left: 0;
max-height: 300px;
margin-bottom: 30px;
font-size: 14px;
line-height: 16px;
font-weight: 400;
width: 100% !important;
background-image: url("data:image/svg+xml,%3Csvg width='12' height='13' viewBox='0 0 12 13' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M2 4.4082L6 8.33026L10 4.4082' stroke='black' stroke-width='2'/%3E%3C/svg%3E%0A");
background-size: 12px;
background-position: right -18px center
}
.msform input[type=checkbox]:focus, .msform input[type=radio]:focus {
outline: 0;
}
.msform input.error, select#country.error {
border-bottom: 1px solid red;
}
input[type=radio].error {
border: 1px solid red !important;
}
label#country-error {
margin-top: -25px;
margin-bottom: 12px;
}
label#property_type_multi-error, label#viable_solution-error, label#switch_reasons-error, label#pms_urgency-error, label#budget_sign_off-error {
position: absolute;
bottom: -37px;
left: -7px;
}
label#contact_type_preference-error {
position: absolute;
left: 25px;
}
.location-wrapper {
margin: 0 auto 30px auto;
display: flex;
align-items: center;
width: 117px;
}
#locationGet:focus {
color: black;
}
#locationGet span {
position: relative;
}
#locationGet img {
max-width: 30px;
position: absolute;
bottom: -5px;
left: -30px;
}
/*buttons*/
.msform .button {
width: 49%;
}
.msform .full-btn {
width: 100%;
}
.pricing-btn-wrapper {
margin-bottom: 40px;
width: 50%;
margin: 0 auto;
}
.pricing-btn-wrapper button:last-child {
border-right-width: 2px;
}
/*headings*/
.fs-title {
font-size: 25px;
text-align: left;
margin-bottom: 40px;
}
.fs-subtitle {
font-weight: normal;
font-size: 13px;
color: #666;
margin-bottom: 20px;
}
/*progressbar*/
.progressbar {
overflow: hidden;
/*CSS counters to number the steps*/
counter-reset: step;
margin-left: 0px;
margin-right: 0px;
}
.progressbar li {
list-style-type: none;
width: 33.33%;
float: left;
position: relative;
}
#progressbar1 {
opacity: 1;
transition: opacity 200ms ease-in-out;
}
#progressbar2 li {
width: 25%;
}
.progressbar li:before {
content: "\A";
width: 20px;
display: block;
border-radius: 50%;
background-color: #e1e2e2;
height: 20px;
margin: 0 auto 5px auto;
}
/*progressbar connectors*/
.progressbar li:after {
content: '';
width: 100%;
height: 2px;
background-color: #e1e2e2;
position: absolute;
left: -50%;
top: 9px;
z-index: -1; /*put it behind the numbers*/
}
.progressbar li:first-child:after {
/*connector not needed before the first step*/
content: none;
}
/*marking active/completed steps green*/
/*The number of the step and the connector before it = green*/
.progressbar li.active:before, .progressbar li.active:after{
background: #fecb2e;
}
.fade {
opacity: 0 !important;
}
#other, #propgroup, .hostel-size, .email-hide {
display: none;
}
#msForm-thanks .button {
margin: 10px auto;
}
@media (max-width: 979px) {
.side-panel {
display: none !important;
}
.main-panel {
padding-left: 0px;
}
}
@media (min-height: 920px) {
.main-panel {
height: 100%
}
}
@media (max-width: 425px) {
.msform {
min-height: 800px;
margin: -30px auto 50px auto;
}
#form2 {
top: 30px;
}
.msform fieldset {
padding: 20px 0px;
}
.msform label {
width: 80%;
}
.radio-container {
flex-direction: column;
}
.radio {
width: 100%
}
.pricing-btn-wrapper {
width: auto;
}
.form-wrapper h1 {
margin: 0 10px 80px;
}
label[for=newsletter] {
width: 100%;
}
.country {
margin-bottom: 20px;
}
#locationGet {
position: static;
top: auto;
right: auto;
font-size: 1em;
}
}
@piersg , that was a unique way of getting two upvotes ![]()
This could truely be genuinely extraordinary. We’ve been doing increasingly ADA compliance for customers and it would simply speed up testing a little to have some built in checks especially in relation page to things the advertising and marketing team or a customer can be editing.