Custom Validation Before Submit

Hey!

I’m currently building a HubSpot form (the new version, not legacy) for my app and need pre-validation.

The form is part of our demo process, and users can specify a desired subdomain. I want to validate this internally upon submission, and if the subdomain is invalid, nothing should be synced.

Is there no “on-before-submit” step where I can perform custom validations and potentially cancel the submission?

Best regards,
Patrick

What type of validation do you want to perform? When does your sync happen?

You can definitely add some javascript to the embed form to do some basic checks but anything complicated (eg, check in hubspot if someone else has the subdomain) wouldn’t likely be available.

Your property field can also have their own custom rules (eq, unique values only) and I believe that would flow back to the form.

You can also have automation that is executed after the user submits to update and/or clear data.

This is actually one of the biggest differences between the legacy and new forms.

Legacy forms exposed an onBeforeFormSubmit callback that could cancel the submission before it was processed. The new forms still expose submission events, but they don’t provide a supported way to stop the submission. Calling preventDefault() on the new form events doesn’t prevent HubSpot from processing the submission.

If your validation depends on an external system, I’d recommend letting the submission complete, marking it as Pending Validation, performing the validation asynchronously, and only continuing the sync if it succeeds.

If preventing the submission entirely is a hard requirement, you’ll likely need to build your own front end instead of relying on the native form.

Thank you all for your Input! Ill try out some of the suggestions. I hope I can create a solution without creating my own form, would be rather complicated to retrieve all additional tracking statistics and send them to hubspot.

I’ll let you know what worked out for me when im done.