These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Submitting form data in body of email

rtrumbore
Registered: Jun 27 2007
Posts: 10

The following is based on examples from Stefan Cameron's article "Submitting Form Data by Email."

Please help. I'm having trouble with a "quick and dirty" form which contains only these 4 fields: “unitId”, “emplName”, “jobTitle”, and “probDesc”. The “TO” and “SUBJECT” fields will have static values. The email body should appear exactly as shown, assuming that the user inputs:

unitId = 110123
emplName = Joe Blow
jobTitle = General Manager
probDesc = The only problem I have to report is that the sky is falling.

The final body msg is show between the lines:

————————————————

%AFFECTED END USER= 110123
%CATEGORY=ServiceDesk
%GROUP=TSC TICKET
%DESCRIPTION=Employee Name: Joe Blow Job Title: General Manager Problem:
The only problem I have to report is that the sky is falling.

———————————————

Here’s the code.

—– form1.#subform[0].Email.Send::click: – (JavaScript, client) —

function GetBody()
{ var body = “Message Body: ” + “\n”;
body += “%AFFECTED END USER= ” + UnitId.Value + “\n”;
body += “%CATEGORY= ” + category.value + “\n”;
body += “%GROUP= ” + group.value + “\n”;
body += “%DESCRIPTION=Employee Name: ” + emplName.value + "Job Title: " + jobTitle.value + "Problem Description: " + probDesc + “\n”;
return body;
};

body = GetBody( );

var newTarget = “mailto:” + to.value + “?” + “body=” + encodeURIComponent(GetBody());
submitNode.target = newTarget;
EmailSubmitButton.execEvent(“click”);

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
What exactly is the problem? There are several dependancies here. The code assumes an email submit button on the form and it also assumes a variable named "submitNode" that represents the submit event in the email button. Where is this variable being set?

If all you want is to send an email with the simple data in the body then you are much better off not using the email submit button at all. Use the "app.mailMsg()" instead. It's much simpler and more straight forward, and there are no dependancies on some other submit button.

app.mailMsg({cTo: to.value, cSubject:"???", cMsg: GetBody()});

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

rtrumbore
Registered: Jun 27 2007
Posts: 10
Thank you for your quick response. Please forgive my ignorance with the subject matter? This is my first exposure to LiveCycle Designer and JavaScript. I am in the process of learning both and it is not obvious to me which event(s) I should associate the code with. The only code in the form is what is posted above. That is:
-------------------------------
GetBody()
{ ... }

var newTarget = “mailto:” + to.value + “?” + “body=” + encodeURIComponent(GetBody());
submitNode.target = newTarget;
EmailSubmitButton.execEvent(“click”);
---------------------------------
I have these questions:

1. Should I place the "app.mailMsg" code immediately after the GetBody() function?
2. Should I keep any of the 3 lines that currently follow the GetBody() function?
3. Should all code be associated with a single event? What is the event?
4. After populating the form, the user will press a button to send email. What code/event should be associated with the Send button.

Thank you very much for indulging my ignorance.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Delete everything after the "GetBody()" function and replace it with the app.mailMsg() function. The code should all be in the click event for your send button.

If you have any problems, first check the JavaScript Console to see if any errors are reported (see links below). The problem is most likely in the body string. So do a test where the body text is something very simple, like a single word. If this works then you know that all you have to do is get the body text fixed up correctly.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

rtrumbore
Registered: Jun 27 2007
Posts: 10
I'm still unable to generate an email. The current error is: lillegal character
15:XFA:form1[0]:RTSC_Auto_Ticket_Rept_lb[0]:Button1[0]:click.

Following is a simplified update on the project details:

These 4 fields are on the form:
unitId, emplName, jobTitle, probDesc

These 2 buttons are on the form:
[show string] this button (for debugging) performs “console println” of the final string.
[Send Email] button sends the final string using something like “app.mailMsg” or “mailto”.

If the form user were to fill-in the form as follows:
-----------------------------------------------------------------------------------
unitId [110123]
emplName = [Joe Blow]
jobTitle = [General Manager]
probDesc = This is a multi-line problem description. The only problem I have to report is that the sky is falling! It hit me on the head!
------------------------------------------------------------------------------------

Then press the form’s [Send Email] button. The resulting email’s body would appear (literally) as follows:

%AFFECTED END USER= 110123
%CATEGORY=ServiceDesk
%GROUP=TSC TICKET
%DESCRIPTION=Employee Name: Joe Blow Job Title: General Manager
This is a multi-line problem description. The only problem I have to report is that the sky is falling! It hit me on the head!


Here’s the code I’m trying to debug:

----- form1.RTSC.Button1::click: - (JavaScript, client) --------------

var category = "Service Desk";
var group = "TSC TICKET";
var to = support [at] somesite [dot] com”;
var subject = “SUBMIT”;

function GetBody()
{ var body = “Message Body: ” + “\n”;
body += “%AFFECTED END USER= ” + unitId.value + “\n”;
body += “%CATEGORY= ” + category.value + “\n”;
body += “%GROUP= ” + group.value + “\n”;
body += “%DESCRIPTION=Employee Name: ” + emplName.value + "Job Title: " + jobTitle.value + "Problem Description: " + probDesc.value + “\n”;
return body;
};

app.mailMsg({cTo: to.value, cSubject: subject.value, cMsg: GetBody()});
rtrumbore
Registered: Jun 27 2007
Posts: 10
Thom,

I just purchased a 1-year membership to pdfscripting .com. I've been working on this "simple form" for 8 days. I began at the detail level and was never able to come up for air and see the big picture. I ended doing cut and paste with examples from the internet. The examples had much more functionality than I needed, so I had to figure out what I could delete without breaking the form. That led me to expend precious time leaning how to use the debugger, before I even understood that which I was debugging. I'm not complaining. I love this stuff. The problem is that my manger won't support me continuing with Acrobat forms if I cannot complete what is certainly a very basic form within 8 days. If I don't get the aforementioned form working by end of day, my manager is going to scrap Adobe Acrobat development. If I do solve the problem I will have sufficient time to learn the material before the next form is due. I appreciate the time of everyone who has contributed.

Best Regards,

Richard
rtrumbore
Registered: Jun 27 2007
Posts: 10
Thanks Thom. Your the greatest man!

For anyone stumbling over this thread: I mentioned above that I made a last ditch effort by joining pdfscripting.com. I struck gold. I met with Thom Parker via GoToMeeting.com. He quickly detected and fixed several problems. We ran the correct code and still got errors. We went over the code again and confirmed it was good. We ran it again and it failed. At that point Thom concluded that the characters appeared correct but were the underlying codes correct? Bingo! I had previously copied code to MS Office and then thoughtlessly pasted rich text data into LiveCycle. The quote marks were unicode chars rather than ASCII. 7 days wasted -- and I knew better.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
For some tips on copying code see my blog, I think I covered this issue:
http://www.acrobatusers.com/blogs/thomp/copying-and-pasting-code

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

MMWilliams
Registered: Aug 23 2010
Posts: 16
I think this is what I'm trying to do with my current form - I want all my form data to populate the body of an email, not uploaded as an attachment.

Can someone help walk me through how to do this?

Thanks
Spleckxa
Registered: Jan 6 2010
Posts: 32
Try this:

event.target.submitForm({cURL:"mailto:"+ vEMail +"&cc="+ vCC +"?Subject=" + vSubject + "&body=" + vBody});//vEmail is the string value(s) of the e-mail address(es) you want to send to, separated by commas;
//vCC is the string value(s) of the e-mail address(es) you want to CC to, separated by commas;
//vSubject is the string value of whatever you want to put in the subject line;
//vBody is the string value of whatever you want to appear in the body of the e-mail message.
//Use "\n" to generate new lines within the body of the e-mail and "\t" to added indentations.
//You must put plus signs "+" between every string value (even for spaces) and every "\n" or "\t" to //properly concatenate (connect) them.

//Here's a sample script on a "click" event for a button (using Javascript):

var vEMail = "John_Doe [at] somecompany [dot] com" + "," + " " + "Susy_Que [at] somehome [dot] com";
var vCC = "Susy_Doe [at] somecompany [dot] org" + "," + " " + "John_Que [at] somehome [dot] com";
var vSubject = "TPI Reports";
var vBody = "Dear John and Susy;" + "\n" + "\n" +
"\t" + "Did you get the memo on the TPI reports?" + "\n" + "\n" +
"Sincerely," + "\n" + "\n" +
"Michael Bolton";

event.target.submitForm({cURL:"mailto:"+ vEMail +"&cc="+ vCC +"?Subject=" + vSubject + "&body=" + vBody});//You can always have the various variables pointing to specific form field raw values on the LCD form.
//For example, var vEmail = form1.page1.textfield1.rawValue will get whatever is in textfield1 and //insert it into the "To" box of the e-mail. You can also concatenate the various raw values of //different fields.

Good luck!
David
Spleckxa
Registered: Jan 6 2010
Posts: 32
Whoops, I just caught a typo in my last e-mail, it should read:

event.target.submitForm({cURL:"mailto:"+ vEMail +"?cc="+ vCC +"&Subject=" + vSubject + "&body=" + vBody});Just switch the "?" and the "&" signs in front of "cc=" and "Subject=".Reason:

"mailto:" parameters, such as "cc=", "bcc=", "Subject=", or "body=" should be preceded by "?" for the first or only parameter and "&" for any subsequent parameter(s).In this case, the first parameter after "mailto:" was "cc=" and the subsequent parameters are "Subject=" and "body="; thus the correct syntax would be "mailto:" ... "?cc="..."&Subject="..."$body="Sorry for the typo.

David