---
title: Form Submit Event Handling
slug: form-submit-event-handling
createdAt: 2025-06-11T20:26:19.223Z
---

The Form\_Submit event is the primary entry point for handling user interactions when a form is submitted. Unlike earlier versions, this event provides a flexible and centralised way to control validation, messaging, navigation, and dynamic behaviour within your forms.

This document outlines common patterns and examples to help you implement custom logic effectively.

## When to Use Form\_Submit

Use the Form\_Submit method when you need to:

- Validate user input beyond standard control validation
- Display custom error messages or feedback
- Perform server-side actions (e.g. sending emails)
- Dynamically modify form data or behaviour
- Control navigation between pages

## Understanding Event Sources

Each action in a form (such as a button click) triggers an event source. You can use this to determine which logic to execute.

:::BlockQuote
if (request.IsEventSource("ValidateName"))
\{
&#x20;   // Logic for ValidateName button
}
:::

This allows a single Form\_Submit method to handle multiple actions cleanly.

## Common Use Cases

### Custom Validation

You can implement custom validation and display errors in different ways depending on the context.

Control-Level Error

Displays an error message directly under a specific control.

:::BlockQuote
request.Page.SetControlError("txtName1", "Can't find user \[" + name + "]");
:::

Use this when the validation relates to a specific input.

Page-Level Error

Displays a general error message at the top of the form.

:::BlockQuote
request.Page.SetPageError("Please select at least one user to request information from.");
:::

Use this when the issue affects the entire form.

Custom Error Display

You can store an error in the job and display it using a custom component such as a help panel.

:::BlockQuote
Job.Arguments.SetValue("\_error", "My Error");
:::

Example component:

:::BlockQuote
\<HelpPanel Title="=/\_error" Visible="=!isnull(=/\_error)">
\</HelpPanel>
:::

### Setting Dynamic Data

You can modify job arguments during submission to dynamically change how the form behaves or what data it uses.

:::BlockQuote
Job.Arguments.SetValue("resource", "=//Resources/Configuration");
:::

The form will regenerate using the updated data.

### Showing Messages to Users

Popup Message (Stay on Page)

:::BlockQuote
request.Page.SetPopupMessage("Email Sent");
:::

Displays a confirmation without reloading or navigating away.

Return to Previous Page with Message

:::BlockQuote
request.Page.ReturnToPreviousPage("Email Sent.");
:::

Returns the user to the previous page and shows a message.

### Navigation Control

You can programmatically control form navigation.

Go to Next Page

:::BlockQuote
Page.RedirectToNextPage();
:::

This is typically used after completing an action successfully.

## Example Implementation

Below is a consolidated example demonstrating multiple use cases within a single Form\_Submit method.

:::BlockQuote
using System;
using Innovation.Activate;
using Activate.Web;
using Activate.Web.Controls;
using Innovation.Activate.Forms.Xaml;

class Script : WebFormScript
\{
&#x20;   public void Form\_Load(object sender, EventArgs e)
&#x20;   \{
&#x20;       ProvisioningTrace.Forms("Form Load");
&#x20;   }

&#x20;   public void Form\_Submit(ActivateHttpRequest request)
&#x20;   \{
&#x20;       ProvisioningTrace.Forms("Form Submit " + request.JobView\.View\.EventSource);

&#x20;       if (request.IsEventSource("GeneratePageError"))
&#x20;       \{
&#x20;           request.Page.SetPageError("Please select at least one user to request information from.");
&#x20;       }

&#x20;       if (request.IsEventSource("ValidateName"))
&#x20;       \{
&#x20;           string name = Job.Arguments.GetString("data/name");
&#x20;           request.Page.SetControlError("txtName1", "Can't find user \[" + name + "]");
&#x20;       }

&#x20;       if (request.IsEventSource("CustomError"))
&#x20;       \{
&#x20;           Job.Arguments.SetValue("\_error", "My Error");
&#x20;       }

&#x20;       if (request.IsEventSource("SetResource"))
&#x20;       \{
&#x20;           Job.Arguments.SetValue("resource", "=//Resources/Configuration");
&#x20;       }

&#x20;       if (request.IsEventSource("SendEmail"))
&#x20;       \{
&#x20;           request.Page.SetPopupMessage("Email Sent");
&#x20;       }

&#x20;       if (request.IsEventSource("SendEmail2"))
&#x20;       \{
&#x20;           request.Page.ReturnToPreviousPage("Email Sent.");
&#x20;       }

&#x20;       if (request.JobView\.View\.EventSource == "GotoNextPage")
&#x20;       \{
&#x20;           Page.RedirectToNextPage();
&#x20;       }
&#x20;   }
}
:::

## Key Takeaways

- Form\_Submit centralises all submission logic
- Use event sources to separate behaviour cleanly
- Choose the appropriate feedback method (control, page, popup, or custom UI)
- Job arguments allow dynamic, data-driven form behaviour
- Navigation can be controlled programmatically
