The following example shows how to extract data from a PDF form submitted with HTTP post and use it to update an employee database. The form was created in LiveCycle Designer.
On the ColdFusion login page, an employee enters a user name and password:
<!--- The following code creates a simple form for entering a user name and password. The code does not include password verification. ---> <h3>Employee Update Login Form</h3> <p>Please enter your user name and password.</p> <cfform name="loginform" action="loginform_procHTTP.cfm" method="post"> <table> <tr> <td>user name:</td> <td><cfinput type="text" name="username" required="yes" message="A user name is required."></td> </tr> <tr> <td>password:</td> <td><cfinput type="password" name="password" required="yes" message="A password is required."></td> </tr> </table> <br/> <cfinput type="submit" name="submit" value="Submit"> </cfform>
On the first processing page, a query retrieves all of the information associated with the user name from the cfdocexamples database. The cfpdfform tag populates an associated PDF form created in LiveCycle Designer (called employeeInfoHTTP.pdf) with the employee name, phone number, e-mail address, and department. The form also includes the employee ID as a hidden field. ColdFusion displays the populated form in the browser where the employee can change personal information in the form and submit it.
<!--- The following code retrieves all of the employee information for the user name entered on the form page. ---> <cfquery name="getEmpInfo" datasource="cfdocexamples"> SELECT * FROM EMPLOYEES WHERE EMAIL = <cfqueryparam value="#FORM.username#"> </cfquery> <!--- The following code populates the template called "employeeInfoHTTP.pdf" with data from the query. As in the previous example, notice the use of the cfpdfsubform tag. The txtEmpID field is a hidden field on the PDF form. ---> <cfquery name="getEmpInfo" datasource="cfdocexamples"> SELECT * FROM EMPLOYEES WHERE EMAIL = <cfqueryparam value="#FORM.username#"> </cfquery> <cfpdfform source="c:\forms\employeeInfoHTTP.pdf" action="populate"> <cfpdfsubform name="form1"> <cfpdfformparam name="txtFirstName" value="#getEmpInfo.FIRSTNAME#"> <cfpdfformparam name="txtLastName" value="#getEmpInfo.LASTNAME#"> <cfpdfformparam name="txtDeptName" value="#getEmpInfo.DEPARTMENT#"> <cfpdfformparam name="txtEmail" value="#getEmpInfo.IM_ID#"> <cfpdfformparam name="txtPhoneNum" value="#getEmpInfo.PHONE#"> <cfpdfformparam name="txtEmpID" value="#getEmpInfo.Emp_ID#"> </cfpdfsubform> </cfpdfform>
When the employee updates the information in the form and clicks the HTTP post Submit button, Acrobat sends the form data (but not the form itself) to a second ColdFusion processing page.
You must reproduce the structure, not just the field name, when you reference form data. To determine the structure of the form data, use the cfdump tag.
<!--- The following code reads the form data from the PDF form and uses it to update corresponding fields in the database. ---> <cfquery name="updateEmpInfo" datasource="cfdocexamples"> UPDATE EMPLOYEES SET FIRSTNAME = "#FORM1.SUBFORM.HEADER.TXTFIRSTNAME#", LASTNAME = "#FORM1.SUBFORM.HEADER.TXTLASTNAME#", DEPARTMENT = "#FORM1.SUBFORM.HEADER.TXTDEPTNAME#", IM_ID = "#FORM1.SUBFORM.HEADER.TXTEMAIL#", PHONE = "#FORM1.SUBFORM.HEADER.TXTPHONENUM#" WHERE EMP_ID = <cfqueryparam value="#FORM1.SUBFORM.TXTEMPID#"> </cfquery> <h3>Employee Information Updated</h3> <p><cfoutput>#FORM1.SUBFORM.HEADER.TXTFIRSTNAME#</cfoutput>,</p> <p>Thank you for updating your employee information in the employee database.</p>