KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Capturing and Maintaining Data from Forms
PRODUCT: 4D | VERSION: 17 | PLATFORM: Mac & Win
Published On: December 11, 2019

This technical tip will discuss how data on a form can be maintained even after closing the form window. The idea is that all of the data stored on the form as form data can be captured within an object that is present outside of the form. This is particularly useful if you want to capture data from forms to work with or to just maintain it.

Suppose you have a customer billing information form and you want to capture the customer's information after they have filled out the form and closed the window. The images below show the form having fields for customers to input their name, home address, and payment method. The customer input is saved inside the form data object as form.name, form.address, and form.payment respectively.





(In this example, the "submit" button has a standard action to close the form window.)

After the customer inputs their information and clicks "submit", the expected behavior is that the form should close and their data should still be maintained in the system. To capture the customer data from the form, the following code can be used:

C_OBJECT($form_data_o)
C_LONGINT($win)
$form_data_o:=New object

$win:=Open form window("YOUR_FORM_NAME")
DIALOG("YOUR_FORM_NAME";$form_data_o)
CLOSE WINDOW($win)

TRACE

The key elements that are used to make this possible are an object variable, DIALOG, and form data. The code opens the form window for the customer to input their information on. It passes in an object ($form_data_o) through DIALOG. This object is used as a container that captures all the data on the form that is stored as form data and maintains it even after the form is closed. Updon closing the form window, the customer information can be found in the object ($form_data_o). A TRACE command is placed after the CLOSE WINDOW call in the sample code to allow us to view the contents of $form_data_o in the debugger after the form window closes.



Upon closing the form window, the debug window shows that the same information that was entered on the form has been maintained outside of the form in $form_data_o. All of the data that was previously stored inside the form data object is now stored in the $form_data_o object.

ex). The data that was stored in form.name is now contained in $form_data_o.name.