Solved

Form data export to email subject line?

Posted on 2006-07-12
19
635 Views
Last Modified: 2011-04-14
Hello experts,

I need to know if it is possible to create a form that will export the data into the subject line of an email.

It would need to be a specific syntax as below:

code[space] numdata/numdata/alphdata/numdata/numdata/numdata/alphdata

You see that it is delimted with slashes only.

I have no problems working with creating forms, however I've never used Acrobat to just access the data and work with it.
It would be nice to stay away from having to use another program to use the data from an XML file. Even if it could just load the data on the clipboard would be acceptable to me.
Is this possible with java scripting native in Acrobat 7 Pro?

0
Comment
Question by:Phosphor
  • 10
  • 9
19 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 17099020
Yes, you can create a "Subject" string for a mail submission of a form. Create a submission button on your form and configure it with an action of "Run JavaScript". The JavaScript you need to execute needs to look like this:

this.submitForm({
    cURL: "mailto:user@some_address.com?subject=test",
    cSubmitAs: "FDF"
});

In this case, I'm only using "test" as the subject, but you can create any subject string you want. Just keep in mind that you may have to escape certain characters for the string to be accepted (e.g. the space).

To get the data from your form fields, you need to use the getField() method:

var firstString = this.getField("theFieldName").value;

Run such a call for every field that you are interested in and collect all the data so that you can create the subject string.
0
 
LVL 1

Author Comment

by:Phosphor
ID: 17099424
Before trying it, it sounds like it should work. What about adding the delimiters? is there a way to insert those while it is constructing the string?

Thanks!
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 250 total points
ID: 17099573
You need to create a string that holds the subject by adding one value at a time. At that time, you would also add the delimiters. It's just a standard JavaScript string concatenation. Here is some sample code that illustrates that:

var field1 = "abc";
var field2 = "def";
var field3 = "xyz";

var finalString = field1 + "/" + field2 + "/" + field3;
console.println(finalString);

In the button action, it would look something like this (this is without getting the actual information from the form fields!):

var field1 = "abc";
var field2 = "def";
var field3 = "xyz";

var finalString = field1 + "/" + field2 + "/" + field3;

// console.println(finalString);  // use this for debugging purposes - it will print a string on the JavaScript console

this.submitForm({
    cURL: "mailto:somebody@address.com?subject=" + finalString,
    cSubmitAs: "FDF"
});

0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 17099608
And one more: to get the space into your string, you need to use %20 instead of the space character:

var subject = "code%20" + dataString;

(This assumes that dataString was created before with all the data that you need to submit).

Don't expect that the email gets send automatically. For security reasons, Acrobat is not submitting forms data via email without some user interaction. It will open a new email in your email client and fill in all the information. The user only has to click on the send button.
0
 
LVL 1

Author Comment

by:Phosphor
ID: 17100495
It works great, Thanks

Is there a way to strip out -or- disable the FDF attachment?

just removing the cSubmitAs: "FDF" doesn't seem to work

Working script below:
var field1 = "ID";
var field2 = "CTemp";
var field3 = "LTemp";

var firstString = this.getField("ID").value;
var firstString = this.getField("CTemp").value;
var firstString = this.getField("LTemp").value;

var finalString = this.getField("ID").value + "/" + this.getField("CTemp").value + "/" + this.getField("LTemp").value;
console.println(finalString); //
this.submitForm({
    cURL: "mailto:so&so@anywhere.com?subject=" + finalString});
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 17101253
No, you are still doing a form submission via email, so the original attachment that contains the forms data has to be there. Acrobat does not know that you are playing tricks with the subject field.

Your code does some extra work: It's sufficient to just get the values once. The variables field1, field2 and field3 are not used, so you don't have to define them. Three lines that assign a value to "firstString" will override the data that's already there, so you don't need these three lines either.
0
 
LVL 1

Author Comment

by:Phosphor
ID: 17102018
Great.

Thanks for your help once again!
0
 
LVL 1

Author Comment

by:Phosphor
ID: 17102624
I there a way to populate the body of the email with the contents of a (new) different field?  I figure it would be a (body="example") but I just don't understand the syntax used. Do I have to create a whole new section for the body with the cURL: "mailto:so&so@anywhere.com?.

I don't think I need another submit form action. Any tips?
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 17102781
Just add the following after the subject line is complete:

+"&body=this%20is%20%20the%20body"

So, given your previous example, it would look like this:

this.submitForm({
    cURL: "mailto:so&so@anywhere.com?subject=" + finalString + +"&body=this%20is%20%20the%20body" });
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:Phosphor
ID: 17103325
For some reason the example above only works when I remove one of the plus signs in the string. But even though that works, if I try to add "&body=("mess") });  to add the contents of another field it says there is a syntax error. Do I need to have a var body= statement connecting the final string & body?
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 17107289
No, body is not a variable, so you don't need a var statement. Are you using a "&" character in your email address? If so, you need to either escape it, or encode it differently because it will corrupt the mailto string. As you can see, the "body" parameter is added after a "&" delimiter, so if you introduce another "&" the mailto handler will split up the line into several (bogus) arguments. The additional plus sign was my mistake. It's a copy&paste error.
Why are you using parenthesis around the body message? Also, you should not use quotes around the actual body string - if you need to, you need to escape the quotes.
0
 
LVL 1

Author Comment

by:Phosphor
ID: 17107779
Here is the actual code so far, If I get rid of the parenthesis I get a syntax error.

Q:<Why are you using parenthesis around the body message?> legacy from +"&body=this%20is%20%20the%20body" it appears that creates the text string.

This code below will give me (mess) in the body where I actually what to populate the value F9 in the body. Another thing that doesn't quite make this work as I need are the fields; 24L & 24S. They need to default to 0.00 & 0.0 respectively, however acrobat wants to truncate these to a whole number (0) when the defaults are used.
Looking through the archives gets me nowhere on this topic. Is there a way to maintain the default settings in the string?


var f1 = this.getField("ID").value;
var f2 = this.getField("CTemp").value;
var f3 = this.getField("LTemp").value;
var f4 = this.getField("Sky").value;
var f5 = this.getField("24L").value;
var f6 = this.getField("24S").value;
var f7 = this.getField("Snow").value;
var f8 = this.getField("Rem").value;
var f9 = this.getField("mess").value;  //added value to place in body

var finalString = this.getField("ID").value + "%20" + this.getField("CTemp").value + "/" + this.getField("LTemp").value + "/" + this.getField("Sky").value + "/" + this.getField("24L").value + "/" + this.getField("24S").value + "/" + this.getField("Snow").value + "/" + this.getField("Rem").value;
console.println(finalString); //
this.submitForm({
    cURL: "mailto:so&so@anywhere.com?subject=" + finalString + "&body=(mess)" });
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 17107953
OK, let's do this one problem at a time.

You are adding the string "&body=(mess)" to your subject line, but you want the value that's stored in the field named "mess" - which you assign to the variable f9. To add this value to your subject, use this command instead: "&body=" + f9
However, as I indicated earlier, you need to make sure that all characters that have to be encoded/escaped are processed correctly. This means that you have to programatically go through the string and e.g. replace all spaces with the sequence %20.

0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 17108087
This page has some information about how to format numbers with two decimals (so that you get the 0.00 in your output):

http://www.irt.org/script/6.htm

0
 
LVL 1

Author Comment

by:Phosphor
ID: 17108348
Would a custom validation script work in the field properties work or would it have to be in the code of the email button?  As a workaround I could possibly change it to a text string and use a comma perhaps but that is messy alternative.

Yes. the "&body=" + f9 is the ticket... works great, Thanks again
.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 17108492
A custom validation script would e.g. limit you to entering just two decimals, but the problem is that the number would still be stored as a number (e.g. 0.00 would be stored as 0). When you retrieve the value, Acrobat (or to be more accurate, the JaveScript interpreter) would only return "0" because it "knows" that 0.00 is basically 0. Other languages have formatting operations that let you specify how you want your string displayed, JavaScript does not (or at least I have not found any yet). That's the reason why you have to manually change the string in case of a 0.

Do the following: Select Advanced>JavaScript>Document JavaScripts... and select to adda new one. Call it "format_00" and click on the "Add..." button.
Paste the following code into that edit window (replacing the original code in the window):

function format_00(value) {
    value-= 0;
    return (value== Math.floor(value)) ? value+ '.00' : (  (value*10 == Math.floor(value*10)) ? value+ '0' : value);
}

Now in your code, calculate the string that you use for field 24L like this:

var f5 = format_00(this.getField("24L").value);

Then, in the line where you assemble the string, use f5 instead of the call to this.getField() - you can actually replace all of the calls with the fX variables:

var finalString = f1 + "%20" + f2 + "/" + f3 + "/" + f4 + "/" + f5 + ...



0
 
LVL 1

Author Comment

by:Phosphor
ID: 17108865
OK that works. Now I seem to have one more problem. basically if a number is not present in any of the number fields it shows NAN (Not A Number). If no measurement can be taken it has to have 3 dashes to let the reviewer know that a measurement was not available. Is this possible to overcome?
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 17109125
Yes. You have to check for an empty string, and replace that with the three dashes. In this case, we have to first treat the input as a string, so try something like this:

var f1 = this.getField("Text1").valueAsString;

if (f1 == "")
{
    f1 = "---";
}
else
{
   f1 = format_00(f1);
}


0
 
LVL 1

Author Comment

by:Phosphor
ID: 17109402
Yep! That's what I needed.

Thanks a lot, I'll be sure to bump your points up even more next go 'round :)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe A recent question here at Experts Exchange piqued my interest, so I decided to provide a thorough solution and publ…
*Adobe Acrobat 9 was used for this article.  Particular steps may vary depending on software versions. Adobe Acrobat has many, many variables that my be utilized to customize your forms for clarity and ease of use. The Form Editing Tool will be y…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
We often encounter PDF files that are pure images, that is, they do not have text characters, but instead contain only raster graphics. The most common causes of this are document scanning software and faxing software/services that create image-only…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now