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

required field validation before sending PDF as email attachment

JORO-David
Registered: Apr 14 2009
Posts: 25

Hello,

I have written the following script in the Actions/Mouse UP section for the 'Email PDF' button I created. When I click the button, I do not get any alert messages for empty required fields, nor do I get an email popup (which I had been able to get prior to deciding to add the required field validation).

Here is my javascript:

var RequiredFields = new Array(17);
RequiredFields[0] = "Adjustability Type";
RequiredFields[1] = "Workstation Type";
RequiredFields[2] = "Range Type";
RequiredFields[3] = "Capacity Type";
RequiredFields[4] = "Base Type";
RequiredFields[5] = "Quantity";
RequiredFields[6] = "Date";
RequiredFields[7] = "Contact Name";
RequiredFields[8] = "Company Name";
RequiredFields[9] = "Company Type";
RequiredFields[10] = "Address";
RequiredFields[11] = "Postal Code / ZIP";
RequiredFields[12] = "City";
RequiredFields[13] = "Province / State";
RequiredFields[14] = "Country";
RequiredFields[15] = "Phone";
RequiredFields[16] = "Email";

var AlertMsg = new Array(17);
AlertMsg[0] = "Please select the type of adjustability you want.";
AlertMsg[1] = "Please select the type of workstation you want.";
AlertMsg[2] = "Please select the amount of range you want.";
AlertMsg[3] = "Please select the amount of capacity you want.";
AlertMsg[4] = "Please select the base (legs) color you want.";
AlertMsg[5] = "Please indicate your estimated order quantity.";
AlertMsg[6] = "Please indicate the date you want your workstations.";
AlertMsg[7] = "Please provide a contact name.";
AlertMsg[8] = "Please provide your company name.";
AlertMsg[9] = "Please select your company type.";
AlertMsg[10] = "Please provide your company's address.";
AlertMsg[11] = "Please provide your company's postal/ZIP code.";
AlertMsg[12] = "Please provide your company's city.";
AlertMsg[13] = "Please provide your company's province/state.";
AlertMsg[14] = "Please provide your company's country.";
AlertMsg[15] = "Please provide the contact's phone #.";
AlertMsg[16] = "Please provide the contact's email address.";

var bSuccess=True
var emptyTest=/^\s*$/;
var fieldCount=RequiredFields.length
var fld=0;

for(var i=0;i

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Have you looked in the Console Window for errors? It's possible that you got one of the required field names wrong. Other than this your code looks good.

You might also want to consider using semicolons where they are missing and indenting the code so it's easier for us to read.

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]

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

JORO-David
Registered: Apr 14 2009
Posts: 25
Hi Thom,

I checked the debugger and this is what the error message was:

ReferenceError: True is not defined
42:AcroForm:SUBMIT_EMAIL:Annot1:MouseUp:Action1


I double-checked all the field names and they appear to be correct. As for missing semi-colons and not indenting, I am new to java script programming and don't yet know the proper formatting techniques/etiquette.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
That's the problem, the bSuccess variable is a boolean value, and it should be set to true, all lower case.

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]

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

JORO-David
Registered: Apr 14 2009
Posts: 25
thanks Thom, that got it working.

The one problem I still have is that even if there is a required field that is empty and I get the error popup, the email with pdf attachment still come up. Have I placed the IF statement to initiate an email incorrectly? I only want an email to be sent if all the required fields have been filled-in.


Thanks so much,
David
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
The equality operator is '==' not '=', so you should be using if(bSuccess == true)
or just if(bSuccess)
for the success test, since the value of 'bSuccess' will eithter be true or false.

George Kaiser

JORO-David
Registered: Apr 14 2009
Posts: 25
Thank you gentlemen, you have helped me to get it working!


I have one more question about this piece of code that I'm hoping you can help me with:

Along with the check for blank fields (the emptyTest var), can I add certain text to my check? For instance, in several drop-downs I have the default starting value as "< SELECT ONE >", which would pass the blank field check, but obviously still isn't appropriate input. If this was Excel, I would simply use an "OR" statement within my "IF" statement, but I'm not sure if I am able to do that in java script.Thanks again!
David.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, if "" is the exact text that's returned by "event.value" then you can add a logicl OR to the "if" test. In JavaScript a logical OR is implemented with "||".For example:

if(emptyTest.test(fld.value) || (event.value == ""))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]

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

JORO-David
Registered: Apr 14 2009
Posts: 25
Perfect!

I used "fld.value" instead of "event.value" and it worked exactly how I wanted it to!


Thanks very much to both of you! This forum is truly a fantastic resource, especially for people like myself who are new to the programming side of Acrobat!
jhurt
Registered: Dec 18 2009
Posts: 1
I'm new to the boards and know just enough JavaScript to get myself in trouble, I've been trying to work with this example, except I am also dealing with another script at the same time. Any ideas how to combine the two?

The follow script works, but when I try to combine it with the validating script above it doesn't work. The script is on the button click event.

var CenterAdress = "";

if (Center.rawValue == "location1")
{
CenterAdress = "mail1 [at] address [dot] com;mail2 [at] address [dot] com";
}
if (Center.rawValue == "location2")
{
CenterAdress = "mail1 [at] address [dot] com;mail2 [at] address [dot] com";
}
if (Center.rawValue == "location3")
{
CenterAdress = "mail1 [at] address [dot] com;mail2 [at] address [dot] com";
}

var myDoc = event.target;
var address = CenterAdress;
var sub = "Document Re-Indexing Request";
var msgBody = "Please make the necessary changes.\n\nThank You\n";

myDoc.mailDoc({
bUI: false,
cTo: address,
cSubject: sub,
cMsg: msgBody,
cSubmitAs: "PDF"
});

Basically I need a form that validates there are no empty fields that can be sent to different people depending on their location. I would appreciate any help or direction.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
The above validation script is written for Acro Forms and not LiveCycle Designer. It appears you are trying to mix Acrobat JavaScript with FormCalc or LiveCycle Designers version of JavaScript.

George Kaiser

zeroxy
Registered: Jan 2 2010
Posts: 1
Thanks very much to both of you!
br27ke
Registered: Nov 12 2009
Posts: 21
Is there any way to do the above validation code in LiveCycle?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, and I think there is already a post on this topic. Do a search on the LiveCycle forum for "Validate Required".

The general idea with form level validation is the same in both technologies. The code walks throught a list of fields, testing the value of each to make sure it is not empty. The only difference between the code here and the same code for a LiveCycle form is that LC doesn't use the "getField()" function and the field value property is "rawValue".

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

kymgardiner
Registered: Nov 24 2010
Posts: 6
Also new to the boards and this topic is exactly what i am trying to achieve. Hitting the Submit button and having the verification of required fields determining if the email is launched or not. The standard Acrobat 'Required Field' behaviour is what I need. Unfortunately this is overridden now I have introduced the below java script. The script deals with the email submission and works perfectly for my needs. What I was wondering is how I could integrate this into Joro Davids script so that if any field is empty it returns to the document and does not allow the email submission. In my tests so far with the above script i get the alert but it still allows me to proceed to emailing.

Any assistance would be greatly appreciated.

My existing code for email subsmission is:

var address = " "
var sub = this.getField("Job Name").value;
var msgBody = "Please find the Job Docket attached.";


Acrobat Pro 9 - Mac OSX 10.6.5

////message box with instructions to add email addresses
var cResponse = app.alert({
cMsg: "To submit this form please click YES. \n\nIn the 'To' field please select the relevant Order Management email address. \n\nYou will be able to add any additional email addresses after you click YES.\n\nClick YES to proceed.\nClick NO to go back and continue editing the Job Docket.",
nIcon: 2, nType: 2,
cTitle: "Emailing Job Docket"});
// proceed only if response is "YES"
if (cResponse == 4) {

this.mailDoc({
bUI: false,
cTo: address,
cSubject: sub,
cMsg: msgBody,
cSubmitAs: "PDF"
});
}