Resetting form after submit using onFormSubmit callback


#1

Why would this be? The API docs say the following: “Callback that executes after form is validated and is ready to submit. This is for any logic that needs to execute after the submit. Any changes will not be validated. Takes the jQuery form object: onFormSubmit($form).”

I’m trying to apply logic (clearing the form) that needs to be executed after the submit. But, the logic is being executed before the data is actually passed to HubSpot because all I see on the HubSpot contact list section are blank entries… If I comment out the onFormSubmit code, it works as expected.

Here’s the actual code too:
hbspt.forms.create({
portalId: ‘2333626’,
formId: ‘9a3ba836-f31f-4869-8d28-d264cc4259a8’,
onFormSubmit: function($form) {
$form[0].reset();
}
});

hbspt.forms.create({
portalId: ‘2333626’,
formId: ‘7ff1f00b-988c-4906-bd48-57ba6851b135’,
target: ‘.newsletter-form’,
onFormSubmit: function($form) {
$form[0].reset();
}
});


#2

Hi @akanshmurthy

That wording is a little misleading. It’s probably more accurate to say that the the function fires when the form is ready to submit (which means all of the fields have passed validation), but just before the data is actually sent. I’ll get the wording updated to better reflect that.

We don’t currently have a hook that would fire after the form data is sent, and specifically for your case, we don’t have a way to clear the form since our forms are designed to redirect to a thank you page, or to replace the form with a thank you message, so in both cases the visitor wouldn’t see the form after submission. Can you tell me more about how you’re using the form and why you’d need to clear it?


#3

@dadams, thanks for the response. Ok, thanks for updating the wording.

Well, the issue is that if we don’t clear the form and the user comes back to the website, the data is already filled out with their prior information. We’d like to clear it because it’s a bad user experience for the form to stay filled out even after it’s submitted. With the current implementation, the form gets cleared before the data is sent.


#4

That’s a feature that’s built into our forms. We’ll automatically populate forms with data from their contact record, so that visitors won’t need to enter duplicate data. If you want to disable that, you can find the instructions for doing so here:


#5

Ok, thanks. I’ll try that.