Calculating form data

The Forms service can calculate the values that a user enters into a form and display the results. To calculate form data, create a form design script that calculates form data. A form design supports three types of scripts. One script type runs on the client, another runs on the server, and the third runs on both the server and the client. The script type discussed in this topic runs on the server. Server-side calculations are supported for HTML, PDF, and Guide (deprecated) transformations.

As part of the form design process, you can make use of calculations and scripts to provide a richer user experience. Calculations and scripts can be added to most form fields and objects.

The user enters values into the form and clicks the Calculate button to view the results. The following process describes an example application that lets a user calculate data:

  • The user accesses an HTML page named StartLoan that acts as the web application’s start page. This page invokes a Java Servlet named GetLoanForm.

  • The GetLoanForm servlet renders a loan form. This form contains a script, interactive fields, a calculate button, and a submit button.

  • The user enters values into the form fields and clicks the Calculate button. The form is sent to the CalculateData Java Servlet where the script is executed. The form is returned to the user with the calculation results displayed in the form.

  • The user continues entering and calculating values until a satisfactory result is displayed. When satisfied, the user clicks the Submit button to process the form. The form is sent to another Java Servlet named ProcessForm that is responsible for retrieving submitted data. (See Handling submitted forms.)

    The following illustration shows the application’s logic flow.

    The steps in the diagram are as follows:

    1. The GetLoanForm Java™ Servlet is invoked from the HTML start page.

    2. The GetLoanForm Java Servlet uses the Forms service Client API to render the loan form to the client web browser. Rendering a form containing a script that is configured to run on the server differs from rendering a form that does not contain a script. The difference is that you must specify the target location that is used to execute the script. If a target location is not specified, a script that is configured to run on the server is not executed. For example, consider the application introduced in this section. The CalculateData Java Servlet is the target location where the script is executed.

    3. The user enters data into interactive fields and clicks the Calculate button. The form is sent to the CalculateData Java Servlet, where the script is executed.

    4. The form is rendered back to the web browser with the calculation results displayed in the form.

    5. The user clicks the Submit button when the values are satisfactory. The form is sent to another Java Servlet named ProcessForm.

      Typically, a form that is submitted as PDF content contains scripts that are executed on the client. However, server-side calculations can also be executed. A Submit button cannot be used to calculate scripts. In this situation, calculations are not executed because the Forms service considers the interaction to be complete.

      To illustrate the usage of a form design script, this section examines a simple interactive form that contains a script that is configured to run on the server. The following illustration shows a form design containing a script. The script adds values that a user enters into the first two fields and displays the result in the third field.

      View full size graphic
      A.
      A field named NumericField1

      B.
      A field named NumericField2

      C.
      A field named NumericField3

      The syntax of the script in this form design is as follows:

          NumericField3 = NumericField2 + NumericField1

      In this form design, the Calculate button is a command button, and the script is located in this button’s Click event. When a user enters values into the first two fields and clicks the Calculate button, the script is executed. The Forms service renders the form back to the client device with the results of the calculation displayed in the NumericField3 field.

      For information about creating a form design script, see Designer Help.

// Ethnio survey code removed