CMS Development

Siyabonga
Member

Embedded form function

SOLVE

Is there a way to ensure that my method inside onFormSubmit has fully run before the forms redirect happens?

0 Upvotes
1 Accepted solution
lscanlan
Solution
HubSpot Alumni
HubSpot Alumni

Embedded form function

SOLVE

Hi @Siyabonga,

 

So far as I know, that's not possible. I believe the form redirect creates a new thread in the browser, which the callback functions don't have access to. There is some time before the redirect happens, so if you're running code that only takes a few milliseconds, the code should run I'd think. But if you're trying to do something that takes more time, like with timeouts or with promises, you could consider adding the redirect into your callback function. And then within the form editor, just select the inline thank you message option instead of the redirect.

 

You've probably seen our docs, but we have those callbacks and events documented here: https://developers.hubspot.com/docs/methods/forms/advanced_form_options and here: https://developers.hubspot.com/global-form-events.

 

If you're having trouble with a specific page, feel free to let me know and link it here.

 

Thanks,

Leland

Leland Scanlan

HubSpot Developer Support

View solution in original post

0 Upvotes
1 Reply 1
lscanlan
Solution
HubSpot Alumni
HubSpot Alumni

Embedded form function

SOLVE

Hi @Siyabonga,

 

So far as I know, that's not possible. I believe the form redirect creates a new thread in the browser, which the callback functions don't have access to. There is some time before the redirect happens, so if you're running code that only takes a few milliseconds, the code should run I'd think. But if you're trying to do something that takes more time, like with timeouts or with promises, you could consider adding the redirect into your callback function. And then within the form editor, just select the inline thank you message option instead of the redirect.

 

You've probably seen our docs, but we have those callbacks and events documented here: https://developers.hubspot.com/docs/methods/forms/advanced_form_options and here: https://developers.hubspot.com/global-form-events.

 

If you're having trouble with a specific page, feel free to let me know and link it here.

 

Thanks,

Leland

Leland Scanlan

HubSpot Developer Support
0 Upvotes