# Form Events

{% hint style="info" %}
**Block Information**

Available in: Page Flow

Toolbox Category: Form

Block Type: [Regular](https://docs.zingy.ai/app-editor/block-anatomy#regular-block)
{% endhint %}

The **`Form Events`** block is used to handle various events related to a form.

<div align="left"><figure><img src="https://3401585094-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmnBepgycwgisXr9ya1N4%2Fuploads%2FsLtZfVjjvrGVREWg4swp%2Fimage.png?alt=media&#x26;token=735d7bda-8767-49b0-919f-5ef8665783c6" alt="" width="239"><figcaption><p>Form Events block</p></figcaption></figure></div>

{% hint style="warning" %}
This block only works when used in *Form* type pages. See [Working With Forms](https://docs.zingy.ai/app-editor/page-editor/working-with-forms) to learn about how forms work.
{% endhint %}

The block consists of *Init Tasks*, Pre-Validate Tasks, *Post-Validate Tasks*, *Submit Tasks*, *Success Tasks* and *Error Tasks* [flow parameters](https://docs.zingy.ai/app-editor/block-anatomy#flow-parameters) which are discussed below.

***

## Init Tasks

The *Init Tasks* [flow parameter](https://docs.zingy.ai/app-editor/block-anatomy#flow-parameters), is used to implement logic during the initialization process of the form.

If you plan on adding logic that takes time to complete (i.e. executes in the background), we recommend locking the form using the [Lock/Unlock Form](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/lock-unlock-form) block and unlocking when the task is complete.

***

## Pre-Validate Tasks

The logic in the *Pre-Validate Tasks* [flow parameter](https://docs.zingy.ai/app-editor/block-anatomy#flow-parameters) is invoked after the user clicks the submit button or when the [Save Form with Data](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/save-form-with-data) is executed without a valid data object attached its [value parameter](https://docs.zingy.ai/app-editor/block-anatomy#value-parameters). This occurs prior to Zingy's automatic field input validation process.

You can implement any supplemental validation or input correction tasks here. &#x20;

* Use the [Get Field Input Value](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/get-field-input-value) or [Get Input Value](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/get-input-value) blocks to retrieve the values entered by the user.
* For any input corrections use the [Set Field Input Value](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/set-field-input-value) or [Set Input Value](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/set-input-value) blocks to set the value.
* Use the [Set Form Event Status](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/set-form-event-status) block by setting its [Dropdown configuration setting](https://docs.zingy.ai/app-editor/block-anatomy#dropdown) to *OK* for continuing with the processing, or *ERROR* to stop further processing.
* You may also use the [Set Form Event Status Message](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/set-form-event-status-message) to report any specific error message to the user.

{% hint style="danger" %}
Please note that you cannot execute a background task and wait for it's completion here.
{% endhint %}

***

## Post-Validate Tasks

The logic in the *Post-Validate Tasks* [flow parameter](https://docs.zingy.ai/app-editor/block-anatomy#flow-parameters) is invoked after Zingy's automatic field input validation process but prior to the submission of the form's data.

* To access the data entered by the user, use the [Form Data](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/form-data) block for both retrieving and setting the values of the fields. At this stage, avoid using the [Set Field Input Value](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/set-field-input-value) or [Set Input Value](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/set-input-value) blocks since the system has already progressed beyond the point of reading field input values.
* Use the [Set Form Event Status](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/set-form-event-status) block by setting its [Dropdown configuration setting](https://docs.zingy.ai/app-editor/block-anatomy#dropdown) to *OK* for continuing with the processing, or *ERROR* to stop further processing.
* You may also use the [Set Form Event Status Message](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/set-form-event-status-message) to report any specific error message to the user.

{% hint style="danger" %}
Please note that you cannot execute a background task and wait for it's completion here.
{% endhint %}

***

## Submit Tasks

The logic in the *Submit Tasks* [flow parameter](https://docs.zingy.ai/app-editor/block-anatomy#flow-parameters) is invoked only in the case of custom forms (where no database table is attached).

Implement your own form data submission or processing logic here. You can access the form's data using the [Form Data](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/form-data) block.

Once you are done processing or submitting the data, use the [Form Submit Complete](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/form-submit-complete) block for the system to proceed with the next step.

Refer to the [Form Submit Complete](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/form-submit-complete) block for an example.

***

## Success Tasks

The *Success Tasks* [flow parameter](https://docs.zingy.ai/app-editor/block-anatomy#flow-parameters) allows you to execute logic when the form's data has been submitted successfully.

* You can use the [Form Data](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/form-data) block to retrieve the data that was submitted.
* You may also use the [Set Form Event Status Message](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/set-form-event-status-message) to report any specific message to the user. This will override the form's success message.

{% hint style="danger" %}
Please note that you cannot execute a background task and wait for it's completion here.
{% endhint %}

***

## Error Tasks

The *Error Tasks* [flow parameter](https://docs.zingy.ai/app-editor/block-anatomy#flow-parameters) allows you to execute logic when there was an error in submitting the form's data.

* You can use the [Form Data](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/form-data) block to retrieve the data entered by the user..
* You may also use the [Set Form Event Status Message](https://docs.zingy.ai/app-editor/page-flow/toolbox-blocks/set-form-event-status-message) to report any specific message to the user. This will override the form's error message.
