APIs & Integrations

AK_SKY
Member

Forms- Is it possible to validate an input with an external source

Would like to validate a fom input with an external source(outside of HubSpot) and then return a message or conditionally show more fields. 

 

a) Is this possible?

b) How to orchestrate this via code?

c) Provide any useful links

1 Reply 1
lscanlan
HubSpot Alumni
HubSpot Alumni

Forms- Is it possible to validate an input with an external source

Hi @AK_SKY,

 

You might be able to do some of this with a HubSpot form. There aren't any built-in events or callbacks for input changes on HubSpot forms, but there is an input event for input elements, which you can read about here: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event. So you could bind a function to the input event of the form field's input element that you're trying to target, where your function would run your custom validation.

 

If you haven't seen the global form events and callbacks exposed by our forms, you can find them here: https://developers.hubspot.com/global-form-events, and https://developers.hubspot.com/docs/methods/forms/advanced_form_options. They're mostly involving submit events for the form though.

 

As for displaying a message, that would need to be custom. The inline thank you message will only display after the form is submitted. But again you could set up events so that a message gets added to the page when something happens (like when an input passes your custom validation). And as for conditional form fields, I don't know that you'll be able to add those based on inputs passing your custom validation. There rae rules that you can add within the form editor, like if your field conatins specific text. But the conditional field actually gets added into the HTML when the condition is met (as opposed to being on the page, but hidden). So it wouldn't be possible to just write CSS for that.

 

If you run into any questions about this, let me know.

 

Leland Scanlan

HubSpot Developer Support
0 Upvotes