Form Submit Event Handling
11 min
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 if (request iseventsource("validatename")) { // 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 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 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 job arguments setvalue(" error", "my error"); example component \<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 job arguments setvalue("resource", "=//resources/configuration"); the form will regenerate using the updated data showing messages to users popup message (stay on page) request page setpopupmessage("email sent"); displays a confirmation without reloading or navigating away return to previous page with message 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 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 using system; using innovation activate; using activate web; using activate web controls; using innovation activate forms xaml; class script webformscript { public void form load(object sender, eventargs e) { provisioningtrace forms("form load"); } public void form submit(activatehttprequest request) { provisioningtrace forms("form submit " + request jobview\ view\ eventsource); if (request iseventsource("generatepageerror")) { request page setpageerror("please select at least one user to request information from "); } if (request iseventsource("validatename")) { string name = job arguments getstring("data/name"); request page setcontrolerror("txtname1", "can't find user \[" + name + "]"); } if (request iseventsource("customerror")) { job arguments setvalue(" error", "my error"); } if (request iseventsource("setresource")) { job arguments setvalue("resource", "=//resources/configuration"); } if (request iseventsource("sendemail")) { request page setpopupmessage("email sent"); } if (request iseventsource("sendemail2")) { request page returntopreviouspage("email sent "); } if (request jobview\ view\ eventsource == "gotonextpage") { page redirecttonextpage(); } } } 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