I have an embedded Hubspot form on a Webflow website.
After the user submits the form, it redirects the user to a Calendly link to schedule a meeting.
I’d like to create a 5-second delay between the form submission and the redirect happening.
I’ve tried adding some JavaScript code to achieve this, but it didn’t work. Here’s the code I tried to use:
Hi @Kevin-C and thanks for your answer.
Currently, I’ve found a way to add the delay to the redirect, but it seems the data is not sent into Hubspot as a submission. So my challenge right now is having the delay to the redirect + having the input sent to Hubspot.
This is my code:
<script>
hbspt.forms.create({
region: "na1",
portalId: "23561857",
formId: "f29794a4-85a6-4d4a-8c07-89b90532521a",
target: "#div-form-holder",
css: "",
onFormReady: function($form) {
$form.submit(function(e) {
e.preventDefault();
// Get the form action URL
var formAction = $form.attr("action");
// Append the submission query string to the action URL
var submissionUrl = formAction + "&hsFormTargetCallback=submitCallback";
// Set the form's action attribute to the new submission URL
$form.attr("action", submissionUrl);
// Submit the form
$form.get(0).submit();
// Redirect after 5 seconds
setTimeout(function() {
window.location.href = "https://meetings.hubspot.com/matan-kaufmann/matans-link?__hstc=139330924.1f1e24dfcc82e314ce96df520b7df8c3.1675680786501.1681816426551.1681996421854.20&__hssc=139330924.1.1681996421854&__hsfp=858832644&submissionGuid=adc5936f-d66f-48f7-b4a0-94836331376d";
}, 5000); // 5000ms = 5s
});
}
});
</script>