Skip to main content

Form submission order: rules, Events and JavaScript

Understand the order in which Formulayt processes field changes, rules, Events and JavaScript during form submission.

Formulayt can trigger logic through rules, scripts added to Events in the platform, and JavaScript added to the page using the client-side API. The order in which they fire depends on what triggers the logic and how the form is submitted.

Before submission

When a user changes a field, Formulayt processes the change in the following order:

Field value changes

↓

"Field changed" Event code triggers

↓

Continuous rules watching the field triggers

Note: Continuous rules on trigger when the condition they are watching changes. They do not trigger again when the user clicks Submit unless the submission itself changes a field they are watching.

During submission

When a valid form is submitted, the following order applies:

Validation completes

↓

"On submission" rules trigger

↓

gcdcGateSubmit on-page code triggers

↓

The submission method takes control

This means that if you have both an On submission rule and a gcdcGateSubmit listener, the rule triggers first.

When submission logic changes a field

An On submission rule can trigger additional continuous rules if it changes a field that those rules are watching.

On submission rule triggers

↓

Rule changes a watched field

↓

Continuous rules trigger

↓

Remaining On submission rules trigger

↓

gcdcGateSubmit on-page code triggers

The same applies to field changes made by gcdcGateSubmit code.

For example:

field.setValue('New value', true);

The true tells Formulayt to process the change. Any continuous rules watching that field trigger before the gcdcGateSubmit handler finishes and submission continues.

After Submission

The Submission Event fires at a different point depending on the submission method.

Fetch submission

Fetch request resolves successfully

↓

Submission Event

↓

gcdcGateSubmitted

Iframe submission

Submission started

↓

Submission Event

↓

gcdcGateSubmitted

Custom integration

Integration reports success

↓

Submission Event

↓

gcdcGateSubmitted

Synchronous submission

Submission Event

↓

Short delay

↓

Payload sent

↓

Page unload

For synchronous submissions, gcdcGateSubmitted does not fire because the page unloads.

The Submission Event and gcdcGateSubmitted indicate that Formulayt has completed its submission work. They do not guarantee that the destination system has accepted or processed the submitted data.

If submission fails

Different Events trigger depending on where the submission fails.

Validation fails when trying to submit the form

  • The Validation failed Event triggers.

  • gcdcGateSubmit does not fire.

  • gcdcGateSubmitted does not fire.

Validation passes but the form cannot be submitted

  • gcdcGateSubmit has already been fired.

  • The Submission failed Event triggers.

  • gcdcGateSubmitted does not fire.

Asynchronous JavaScript

Formulayt waits for normal synchronous JavaScript inside gcdcGateSubmit, but it does not wait for asynchronous operations such as fetch().

If a field needs to be changed before the submission takes place, make that change synchronously inside the gcdcGateSubmit handler.

Did this answer your question?