HTML Forms fires several JavaScript events when visitors interact with a form on your site. You can hook into these events to run your own code, for example to send events to Google Analytics.

Available form events

The following events are available.


Fires right after the form is submitted, but before the request is processed.


Fires after the request is processed, for both successful submissions and errors.


Fires after the request is processed when a validation error occurs, eg a required field is missing.


Fires after the request is processed and the submission was a success.

Hooking into an event

The following code example hooks into the "success" event (see above).

html_forms.on('success', function(formElement) {
   // your code goes here

You can add this code directly to your form mark-up or to any other JavaScript file that is loaded on your site.

Was this article helpful? ·