Handling Submitted Forms handling-submitted-forms
Samples and examples in this document are only for AEM Forms on JEE environment.
Web-based applications that enable a user to fill in interactive forms require the data to be submitted back to the server. Using the Forms service, you can retrieve the data that the user entered into an interactive form. After you retrieve the data, you can process the data to meet your business requirements. For example, you can store the data in a database, send the data to another application, send the data to another service, merge the data in a form design, display the data in a web browser, and so on.
Form data is submitted to the Forms service as either XML or PDF data, which is an option that is set in Designer. A form that is submitted as XML enables you to extract individual field data values. That is, you can extract the value of each form field that the user entered into the form. A form that is submitted as PDF data is binary data, not XML data. You can save the form as a PDF file, or send the form to another service. If you want to extract data from a form submitted as XML and then use the form data to create a PDF document, invoke another AEM Forms operation. (See Creating PDF Documents with Submitted XML Data)
The following diagram shows data being submitted to a Java Servlet named HandleData from an interactive form displayed in a web browser.
The following table explains the steps in the diagram.
HandleData Java Servlet as XML data.HandleData Java Servlet contains application logic to retrieve the data.Handling submitted XML data handling-submitted-xml-data
When form data is submitted as XML, you can retrieve XML data that represents the submitted data. All form fields appear as nodes in an XML schema. The node values correspond to the values that the user filled in. Consider a loan form where each field in the form appears as a node within the XML data. The value of each node corresponds to the value that a user fills in. Assume a user fills the loan form with data shown in the following form.
The following illustration shows corresponding XML data that is retrieved by using the Forms service Client API.
The fields in the loan form. These values can be retrieved
using Java XML classes.
Handling submitted PDF data handling-submitted-pdf-data
Consider a web application that invokes the Forms service. After the Forms service renders an interactive PDF form to a client web browser, the user fills in the form and submits it back as PDF data. When the Forms service receives the PDF data, it can send the PDF data to another service or save it as a PDF file. The following diagram shows the application’s logic flow.
The following table describes the steps in this diagram.
Handling submitted URL UTF-16 data handling-submitted-url-utf-16-data
If form data is submitted as URL UTF-16 data, the client computer requires Adobe Reader or Acrobat 8.1 or later. Also if the form design contains a submit button that has URL-encoded Data (HTTP Post) and the data encoding option is UTF-16, the form design must be modified in a text editor such as Notepad. You can set the encoding option to either UTF-16LE or UTF-16BE for the submit button. Designer does not provide this functionality.
Summary of steps summary-of-steps
To handle submitted forms, perform the following tasks:
- Include project files.
- Create a Forms Client API object.
- Retrieve form data.
- Determine if the form submission contains file attachments.
- Process the submitted data.
Include project files
Include necessary files into your development project. If you are creating a client application using Java, include the necessary JAR files. If you are using web services, ensure that you include the proxy files.
Create a Forms Client API object
Before you can programmatically perform a Forms service Client API operation, you must create a Forms service client. If you are using the Java API, create a FormsServiceClient object. If you are using the Forms web service API, create a FormsService object.
Retrieve form data
To retrieve submitted form data, you invoke the FormsServiceClient object’s processFormSubmission method. When invoking this method, you have to specify the submitted form’s content type. When data is submitted from a client web browser to the Forms service, it can be submitted as either XML or PDF data. To retrieve the data that is entered into form fields, the data can be submitted as XML data.
You can also retrieve form fields from a form submitted as PDF data by setting the following run-time options:
- Pass the following value to the
processFormSubmissionmethod as the content type parameter:CONTENT_TYPE=application/pdf. - Set the
RenderOptionsSpecobject’sPDFToXDPvalue totrue - Set the
RenderOptionsSpecobject’sExportDataFormatvalue toXMLData
You specify the content type of the submitted form when you invoke the processFormSubmission method. The following list specifies applicable content type values:
- text/xml: Represents the content type to use when a PDF form submits form data as XML.
- application/x-www-form-urlencoded: Represents the content type to use when an HTML form submits data as XML.
- application/pdf: Represents the content type to use when a PDF form submits data as PDF.
application/pdf. The Handling PDF forms submitted as XML using the Java API quick start demonstrates how to handle submitted XML data that is submitted from a PDF form. The content type specified in this quick start is text/xml. Likewise, the Handling HTML forms submitted as XML using the Java API quick start demonstrates how to handle submitted XML data that is submitted from an HTML form. The content type specified in this quick start is application/x-www-form-urlencoded.You retrieve form data that was posted to the Forms service and determine its processing state. That is, when data is submitted to the Forms service, it does not necessarily mean that the Forms service is finished processing the data and the data is ready to be processed. For example, data can be submitted to the Forms service so that a calculation can be performed. When the calculation is complete, the form is rendered back to the user with the calculation results displayed. Before you process submitted data, it is recommended that you determine whether the Forms service has finished processing the data.
The Forms service returns the following values to indicate whether it has finished processing the data:
- 0 (Submit): Submitted data is ready to be processed.
- 1 (Calculate): The Forms service performed a calculation operation on the data and the results must be rendered back to the user.
- 2 (Validate): The Forms service validated form data and the results must be rendered back to the user.
- 3 (Next): The current page has changed with results that must be written to the client application.
- 4 (Previous): The current page has changed with results that must be written to the client application.
Determine if the form submission contains file attachments
Forms submitted to the Forms service can contain file attachments. For example, using Acrobat’s built-in attachment pane, a user can select file attachments to submit along with the form. As well, a user can also select file attachments using an HTML toolbar that is rendered with an HTML file.
After you determine if a form contains file attachments, you can process the data. For example, you can save the file attachment to the local file system.
Process the submitted data
Depending on the content type of the submitted data, you can extract individual form field values from the submitted XML data or save the submitted PDF data as a PDF file (or send it to another service). To extract individual form fields, convert submitted XML data to an XML data source and then retrieve XML data source values by using org.w3c.dom classes.
See also
Including AEM Forms Java library files
Forms Service API Quick Starts
Handle submitted forms using the Java API handle-submitted-forms-using-the-java-api
Handle a submitted form by using the Forms API (Java):
-
Include project files
Include client JAR files, such as adobe-forms-client.jar, in your Java project’s class path.
-
Create a Forms Client API object
- Create a
ServiceClientFactoryobject that contains connection properties. - Create an
FormsServiceClientobject by using its constructor and passing theServiceClientFactoryobject.
- Create a
-
Retrieve form data
- To retrieve form data that was posted to a Java Servlet, create a
com.adobe.idp.Documentobject by using its constructor and invoking thejavax.servlet.http.HttpServletResponseobject’sgetInputStreammethod from within the constructor. - Create a
RenderOptionsSpecobject by using its constructor. Set the locale value by invoking theRenderOptionsSpecobject’ssetLocalemethod and passing a string value that specifies the locale value.
note note NOTE You can instruct the Forms service to create XDP or XML data from submitted PDF content by invoking the RenderOptionsSpecobject’ssetPDF2XDPmethod and passingtrueand also callingsetXMLDataand passingtrue. You can then invoke theFormsResultobject’sgetOutputXMLmethod to retrieve the XML data that corresponds to the XDP/XML data. (TheFormsResultobject is returned by theprocessFormSubmissionmethod, which is explained in the next sub-step.)-
Invoke the
FormsServiceClientobject’sprocessFormSubmissionmethod and pass the following values:- The
com.adobe.idp.Documentobject that contains the form data. - A string value that specifies environment variables including all relevant HTTP headers. Specify the content type to handle. To handle XML data, specify the following string value for this parameter:
CONTENT_TYPE=text/xml. To handle PDF data, specify the following string value for this parameter:CONTENT_TYPE=application/pdf. - A string value that specifies the
HTTP_USER_AGENTheader value, for example, .Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322). This parameter value is optional. - A
RenderOptionsSpecobject that stores run-time options.
The
processFormSubmissionmethod returns aFormsResultobject containing the results of the form submission. - The
-
Determine whether the Forms service is finished processing the form data by invoking the
FormsResultobject’sgetActionmethod. If this method returns the value0, the data is ready to be processed.
- To retrieve form data that was posted to a Java Servlet, create a
-
Determine if the form submission contains file attachments
- Invoke the
FormsResultobject’sgetAttachmentsmethod. This method returns ajava.util.Listobject that contains files that were submitted with the form. - Iterate through the
java.util.Listobject to determine if there are file attachments. If there are file attachments, each element is acom.adobe.idp.Documentinstance. You can save the file attachments by invoking thecom.adobe.idp.Documentobject’scopyToFilemethod and passing ajava.io.Fileobject.
note note NOTE This step is only applicable if the form is submitted as PDF. - Invoke the
-
Process the submitted data
-
If the data content type is
application/vnd.adobe.xdp+xmlortext/xml, create application logic to retrieve XML data values.- Create a
com.adobe.idp.Documentobject by invoking theFormsResultobject’sgetOutputContentmethod. - Create a
java.io.InputStreamobject by invoking thejava.io.DataInputStreamconstructor and passing thecom.adobe.idp.Documentobject. - Create an
org.w3c.dom.DocumentBuilderFactoryobject by calling the staticorg.w3c.dom.DocumentBuilderFactoryobject’snewInstancemethod. - Create an
org.w3c.dom.DocumentBuilderobject by invoking theorg.w3c.dom.DocumentBuilderFactoryobject’snewDocumentBuildermethod. - Create an
org.w3c.dom.Documentobject by invoking theorg.w3c.dom.DocumentBuilderobject’sparsemethod and passing thejava.io.InputStreamobject. - Retrieve the value of each node within the XML document. One way to accomplish this task is to create a custom method that accepts two parameters: the
org.w3c.dom.Documentobject and the name of the node whose value you want to retrieve. This method returns a string value representing the value of the node. In the code example that follows this process, this custom method is calledgetNodeText. The body of this method is shown.
- Create a
-
If the data content type is
application/pdf, create application logic to save the submitted PDF data as a PDF file.- Create a
com.adobe.idp.Documentobject by invoking theFormsResultobject’sgetOutputContentmethod. - Create a
java.io.Fileobject by using its public constructor. Be sure to specify PDF as the file name extension. - Populate the PDF file by invoking the
com.adobe.idp.Documentobject’scopyToFilemethod and passing thejava.io.Fileobject.
- Create a
-
See also
Quick Start (SOAP mode): Handling PDF forms submitted as XML using the Java API
Quick Start (SOAP mode): Handling HTML forms submitted as XML using the Java API
Quick Start (SOAP mode): Handling PDF forms submitted as PDF using the Java API
Handle submitted PDF data using the web service API handle-submitted-pdf-data-using-the-web-service-api
Handle a submitted form by using the Forms API (web service):
-
Include project files
- Create Java proxy classes that consume the Forms service WSDL.
- Include the Java proxy classes into your class path.
-
Create a Forms Client API object
Create a
FormsServiceobject and set authentication values. -
Retrieve form data
-
To retrieve form data that was posted to a Java Servlet, create a
BLOBobject by using its constructor. -
Create a
java.io.InputStreamobject by invoking thejavax.servlet.http.HttpServletResponseobject’sgetInputStreammethod. -
Create a
java.io.ByteArrayOutputStreamobject by using its constructor and passing the length of thejava.io.InputStreamobject. -
Copy the contents of the
java.io.InputStreamobject into thejava.io.ByteArrayOutputStreamobject. -
Create a byte array by invoking the
java.io.ByteArrayOutputStreamobject’stoByteArraymethod. -
Populate the
BLOBobject by invoking itssetBinaryDatamethod and passing the byte array as an argument. -
Create a
RenderOptionsSpecobject by using its constructor. Set the locale value by invoking theRenderOptionsSpecobject’ssetLocalemethod and passing a string value that specifies the locale value. -
Invoke the
FormsServiceobject’sprocessFormSubmissionmethod and pass the following values:- The
BLOBobject that contains the form data. - A string value that specifies environment variables including all relevant HTTP headers. Specify the content type to handle. To handle XML data, specify the following string value for this parameter:
CONTENT_TYPE=text/xml. To handle PDF data, specify the following string value for this parameter:CONTENT_TYPE=application/pdf. - A string value that specifies the
HTTP_USER_AGENTheader value; for example,Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322). - A
RenderOptionsSpecobject that stores run-time options. - An empty
BLOBHolderobject that is populated by the method. - An empty
javax.xml.rpc.holders.StringHolderobject that is populated by the method. - An empty
BLOBHolderobject that is populated by the method. - An empty
BLOBHolderobject that is populated by the method. - An empty
javax.xml.rpc.holders.ShortHolderobject that is populated by the method. - An empty
MyArrayOf_xsd_anyTypeHolderobject that is populated by the method. This parameter is used to store file attachments that are submitted along with the form. - An empty
FormsResultHolderobject that is populated by the method with the form that is submitted.
The
processFormSubmissionmethod populates theFormsResultHolderparameter with the results of the form submission. - The
-
Determine whether the Forms service is finished processing the form data by invoking the
FormsResultobject’sgetActionmethod. If this method returns the value0, the form data is ready to be processed. You can get aFormsResultobject by getting the value of theFormsResultHolderobject’svaluedata member.
-
-
Determine if the form submission contains file attachments
Get the value of the
MyArrayOf_xsd_anyTypeHolderobject’svaluedata member (theMyArrayOf_xsd_anyTypeHolderobject was passed to theprocessFormSubmissionmethod). This data member returns an array ofObjects. Each element within theObjectarray is anObjectthat corresponds to the files that were submitted along with the form. You can get each element within the array and cast it to aBLOBobject. -
Process the submitted data
-
If the data content type is
application/vnd.adobe.xdp+xmlortext/xml, create application logic to retrieve XML data values.- Create a
BLOBobject by invoking theFormsResultobject’sgetOutputContentmethod. - Create a byte array by invoking the
BLOBobject’sgetBinaryDatamethod. - Create a
java.io.InputStreamobject by invoking thejava.io.ByteArrayInputStreamconstructor and passing the byte array. - Create an
org.w3c.dom.DocumentBuilderFactoryobject by calling the staticorg.w3c.dom.DocumentBuilderFactoryobject’snewInstancemethod. - Create an
org.w3c.dom.DocumentBuilderobject by invoking theorg.w3c.dom.DocumentBuilderFactoryobject’snewDocumentBuildermethod. - Create an
org.w3c.dom.Documentobject by invoking theorg.w3c.dom.DocumentBuilderobject’sparsemethod and passing thejava.io.InputStreamobject. - Retrieve the value of each node within the XML document. One way to accomplish this task is to create a custom method that accepts two parameters: the
org.w3c.dom.Documentobject and the name of the node whose value you want to retrieve. This method returns a string value representing the value of the node. In the code example that follows this process, this custom method is calledgetNodeText. The body of this method is shown.
- Create a
-
If the data content type is
application/pdf, create application logic to save the submitted PDF data as a PDF file.- Create a
BLOBobject by invoking theFormsResultobject’sgetOutputContentmethod. - Create a byte array by invoking the
BLOBobject’sgetBinaryDatamethod. - Create a
java.io.Fileobject by using its public constructor. Be sure to specify PDF as the file name extension. - Create a
java.io.FileOutputStreamobject by using its constructor and passing thejava.io.Fileobject. - Populate the PDF file by invoking the
java.io.FileOutputStreamobject’swritemethod and passing the byte array.
- Create a
-
See also
Invoking AEM Forms using Base64 encoding