APIs & Integrations

Not applicable

Ajax request on embedded form submit?

Hi,

I need to process some data before submitting the form. I am making an AJAX request inside “onFormSubmit”.

But if the AJAX fails the form should not be submitted. I can not make the request synchronous as it is deprecated.

Or if the form gets submitted before the AJAX request is complete I will loose those data. What would be the best way to process this?

Also I need to implement some google conversion code when the button gets clicked. Should I do it in the same section?

0 Upvotes
7 Replies 7
Not applicable

Ajax request on embedded form submit?

Ok. Thank you! :slight_smile:

0 Upvotes
Not applicable

Ajax request on embedded form submit?

Hi,

Any update on this?

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

Ajax request on embedded form submit?

@sougata_bose The best way t handle asynchronous logic that will determine the form submission or not would be to use a custom form and have the HubSpot Forms API post call in the callback to your AJAX call. The HubSpot Form would submit before the AJAX promise would be returned.

0 Upvotes
Not applicable

Ajax request on embedded form submit?

We want to use progressive profiling. Using embedded form would save a lot of work for that.
Is there any other workaround?

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

Ajax request on embedded form submit?

@sougata_bose Progressive Profiling is already built into the tool. You can set it up in the UI and it does not involve any coding to accomplish.

0 Upvotes
Not applicable

Ajax request on embedded form submit?

Yes, but we send emails depending on the data user submits. User can submit multiple forms with different data. We send emails depending on them from workflows. But if a user is already enrolled and submits another form the data would be overwritten.

We will use this ajax request to check if the user is already in the queue and if yes then store the data in our database so that we can update the data later when user completes the workflow.

For this reason we need this ajax request. But if the form gets submit before the request gets complete, may be we will loose the data.

0 Upvotes
3PETE
HubSpot Employee
HubSpot Employee

Ajax request on embedded form submit?

@sougata_bose We don’t allow cross-origin requests for our API. Your calls would have to be made server-side. If you want to check the contact’s property values prior to submission you will need a custom form that can then send the submission data server-side and check the Contacts API before submitting the data to the Forms API.

0 Upvotes