Collecting PDF Form Data via Email: Simple Scripts on the Client-Side

In this column I'll concentrate on some client-side techniques you can use to collect data entered into your PDF forms. My last column focused on the FDF (forms data format) toolkit and how to use it to capture data entered by users. I?ve received a number of emails requesting client-side solutions that don?t require extensive scripting. So rather than continuing with the FDF toolkit (as promised), I?ll instead focus on the other methods of capturing form data that doesn?t require the use of FDF or the FDF toolkit.

I?ll illustrate these capabilities with three tutorials to submit form data via email. All the examples make use of Acrobat?s JavaScript programming language. Another version of the basic example (used in examples #1 & #2) can also be found in the mailto.pdf file on Acrobat 4?s CD-ROM.

First, if you haven?t read the last column, you might want to start there.

The simplest method of transferring data on the Internet is email. However, email allows the user too much "flexibility" in data entry. Since a user can enter whatever information they want in any format, it isn?t very good for forms. One of the earliest CGI applications collected HTML form data and sent it to an email address via email. While you can emulate this form to email method, as illustrated in my last column, there is an alternative.

Example 1: Send Form Data Via the User?s Email Client

In this example we?ll use Acrobat?s JavaScript scripting language, to collect data from a PDF form and send it to an email address. The web form calls the user?s default email client and attaches the form data to the email file.

For this example below to work, the user must have an email client installed.

View the completed example here.

  1. Create a PDF file or open an existing PDF file. You?ll create your PDF form in this document.
  2. Build your PDF form. If you?re not sure how to create a PDF form see Adobe's Form Tutorials.
  3. On your form, create a field named "To" (field names are case-sensitive) where the user can enter the email address of the email?s recipient. Also create a field name "Body" for the text of the message.
  4. Next, create a button that a user can click on to send their email. Set the name of the button to "Send" or another appropriate label.
  5. In the button?s properties (opened when the button is created, or when double-clicked with the field tool active), click on the Actions tab.
  6. In the Actions tab, select the Mouse Up action.
  7. Click Add and select the JavaScript option from the list.
  8. Click the Edit button and the JavaScript below into the dialog:
  9. var to = this.getField("To");

    this.submitForm("mailto:" + to.value, false, false, ["Body"]);

  10. Click OK
  11. Click Set Action
  12. Click OK
  13. Try out the form!

Example 2: Send Form Data Via MAPI Email

In the example above, the user must manually send the email. Additionally, they could edit the email To form and other fields. A more controlled solution can be accomplished via MAPI (Messaging API). MAPI is a programming interface from Microsoft that enables a client application to send to and receive mail from a MAPI enabled messaging system such as Exchange Server or a Microsoft Mail (MS Mail). There are a few third party applications that support this such as the latest releases of Eudora Mail, CC:mail, Netscape Mail, and Outlook Express. Often messaging applications will have a setting in their options that say, Make this my Simple MAPI client. Make sure this is turned on.

The user must be able to connect to a MAPI messaging system for this example to work.

If you created a form in Example 1, you can re-use it for this example. View the completed example here.

  1. Create a PDF file or open an existing PDF file. You?ll create your PDF form in this document.
  2. Build your PDF form. If you?re not sure how to create a PDF form see see Adobe's Form Tutorials.
  3. .
  4. On your form, create a field named "To" where the user can enter the email address of the email?s recipient. Also create a field name "Body" for the text of the message.
  5. Next, create a button that a user can click on to send their email. Set the name of the button to "Send" or another appropriate label.
  6. In the button?s properties (opened when the button is created, or when double-clicked with the field tool active), click on the Actions tab.
  7. In the Actions tab, select the Mouse Up action.
  8. Click Add and select the JavaScript option from the list.
  9. Click the Edit button and the JavaScript below into the dialog:
  10. var to = this.getField("To");

    var body = this.getField("Body");

    app.mailMsg(false, to.value, null, null, "Test Msg", body.value);

  11. Click OK
  12. Click Set Action
  13. Click OK
  14. Try out the form!

To prevent the user from being able to make changes in who the form data is mailed to, edit the To field properties to be locked and hidden.

These two working examples should give you the basics on how to build a PDF form, collect the form data, and send it via email.

Example 3: Advanced Form

The first two examples used only two text fields. Certainly any useful application of Acrobat forms sent via email will have many more fields and possibly a combination of field types.

The third example shows a more functional form, common to e-commerce sites. Instead of a step-by-step guide for creating this form, open the form up and look at the anatomy. The form consists of 9 user-input text fields, one checkbox, one list (with several items in the list), and three radio buttons (all in the same family). Additionally, the form has labels and other formatting and the two submit buttons.

While this form is considerably more complex, the script for it is not (but it is a bit longer). The script of the MAPI version is a bit longer, given all the fields. Here?s the JavaScript code associated with the Mouse Up action of each button.

View the completed advanced example here.

Client-based email button JavaScript code:

var to = this.getField("To");

this.submitForm("mailto:" + to.value, false, true, []);

MAPI-based email button JavaScript code:

var to = this.getField("To");

var namev = this.getField("Name");

var titlev = this.getField("Title");

var companyv = this.getField("Company");

var addressv = this.getField("Address");

var address2v = this.getField("Address2");

var cityv = this.getField("City");

var statev = this.getField("State");

var zipv = this.getField("ZIP");

var checkv = this.getField("check");

var listv = this.getField("list");

var ccv = this.getField("CC");

var formresults = namev.value + ", " + titlev.value + ", " + companyv.value + ", " + addressv.value + ", " + address2v.value + ", " + cityv.value + ", " + statev.value + ", " + zipv.value + ", " + checkv.value + ", " + listv.value + ", " + ccv.value;

app.mailMsg(false, to.value, null, null, "Order", formresults);

The MAPI version requires that we "get" the value of each form field we want (note that there are other form fields that labels). Each of the values of the fields is concatenated in a variable called "formresults". We then export all the fields in the email.

What next?

Now that you have the form data, what do you do with it? Well, that?s up to you. Note that the form data comes URL-encoded. That is, the text comes encoded in such a way that CGI scripts or other web-savvy applications can read the text. If you want plain text, you?ll need to parse the text. You may also want to parse out any "extraneous" fields, such as the labels and their default values.

If you?ve got questions, I?ll do my best to answer them. Please let me know what you think of this column and how I can improve it. Contact me at gordon_kent@yahoo.com.

PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Aerialist 11

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link...

Download free demo

Debenu PDF Tools Pro

It's simple to use and will let you preview and edit PDF files, it's a Windows application that makes...

Download free demo

Two Passwords Are Better Than One: The Low-Down On PDF Security

For people who don't spend their time looking at PDF files in text editors*, PDF security is a sometimes misunderstood beast.

For example, those document restrictions that PDF files sometimes have -- no Printing, Content Copying, Page Extraction, etc -- are essentially useless unless the PDF also has a User Password.

January 09, 2014
Platinum Sponsor



Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist 11

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.

Features

Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.