Form data export to email subject line?

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?

LVL 1
PhosphorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Karl Heinz KremerCommented:
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
PhosphorAuthor Commented:
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
Karl Heinz KremerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Karl Heinz KremerCommented:
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
PhosphorAuthor Commented:
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
Karl Heinz KremerCommented:
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
PhosphorAuthor Commented:
Great.

Thanks for your help once again!
0
PhosphorAuthor Commented:
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
Karl Heinz KremerCommented:
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
PhosphorAuthor Commented:
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
Karl Heinz KremerCommented:
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
PhosphorAuthor Commented:
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
Karl Heinz KremerCommented:
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
Karl Heinz KremerCommented:
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
PhosphorAuthor Commented:
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
Karl Heinz KremerCommented:
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
PhosphorAuthor Commented:
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
Karl Heinz KremerCommented:
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
PhosphorAuthor Commented:
Yep! That's what I needed.

Thanks a lot, I'll be sure to bump your points up even more next go 'round :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Acrobat

From novice to tech pro — start learning today.