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

Javascript Idiot

stonesrock
Registered: Feb 27 2007
Posts: 54

Okay, don't ask me why, I just get totally dumbfounded by Java syntax and can't get past this.

I've found a great form validation script, which in a dummy form I've built, works great. I call the function on a "Validate" button and it works fine when a required field doesn't isn't filled in.

Here is the issue I'm having and just can't figure out. I want to add the function to my Email Form button and if there is missing information, it will stop the email script, run the validation script, good to go.

My email script is as follows:

{
//Send mail action
myDoc.mailDoc({
bUI: false,
cTo: address,
cSubject: subject,
cMsg: msgBody,
cSubmitAs: "PDF"
});
}

Thanks for anyone who can help with this, I have to take a Java class.

bluebird_9
Registered: Mar 17 2010
Posts: 2
sample code (Acrobat Javascript)

if (this.getField("FromAddress").value != '' && this.getField("ToAddress").value != '')
{
myDoc.mailDoc({
bUI: false,
cTo: "email [at] email [dot] com",
cSubject: "Subject",
cMsg: "Body of email",
cSubmitAs: "PDF"
});

}
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
It looks like you have set any values to the variables 'address', 'subject', 'body'.

var address = '<span class="spamspan"><span class="u">first [dot] last</span> [at] <span class="d">example [dot] com</span></span>'; // set email address string valuevar subject = 'My Subject Text'; // set the value for the subjectvar msgBody = "This is the message for the email body. My second line."; // text for body of email//Send mail actionmyDoc.mailDoc({bUI: false,cTo: address,cSubject: subject,cMsg: msgBody,cSubmitAs: "PDF"});

George Kaiser

stonesrock
Registered: Feb 27 2007
Posts: 54
I guess I didn't clarify the code better.

I have the variables getting passed to the email portion of the code, here is what I have. The call to function (controller.validateForm(1)) is doing the form validation. This works on it's own, it is just when I try to nest it with the email function:

controller.validateForm(1)

//Variables to be used in the mail context
var rFirstName = resolveNode("root.P1.subfrm_AllSubs.subFrm_GeneralInfo.DataEntryFirstName").rawValue
var rLastName = resolveNode("root.P1.subfrm_AllSubs.subFrm_GeneralInfo.DataEntryLastName").rawValue
var myDoc = event.target;
var address = "AnEmail [at] something [dot] com";
var subject = "Form Submission from " + rFirstName + " " + rLastName;
var msgBody = "Form Name. ";

{
//Send mail action
myDoc.mailDoc({
bUI: false,
cTo: address,
cSubject: subject,
cMsg: msgBody,
cSubmitAs: "PDF"
});
}

I'm stuck on calling the form valiation function first, then jump to email once validaiton corrections (or not) are done.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
What errors are you getting?

What is not working?

Do you test for the passing or failing of the validation script?

Have you looked at the security restrictions detailed in the Acrobat JavaScript API Reference?

Quote:
Note:(Acrobat 7.0) When this method is executed in a non-privileged context, the bUI parameter is not honored and defaults to true. See “Privileged versus non-privileged context” on page 32 for details.(Save Rights) For Adobe Reader 5.1 and later, this method is allowed, but document Save rights are required in case the document is changed.

On Windows, the client computer must have its default mail program configured to be MAPI enabled to use this method.

George Kaiser

stonesrock
Registered: Feb 27 2007
Posts: 54
Basically, I'm lost in the syntax, both pieces (validation and email) of code work. I want to:

Validate Form and if it validated, then email the form. If not, let the user fix the missing data that is highlighted from form Validation.

What happens once I hit the button (I want to have one button "Email", I don't want to depend on users hitting validate button) is that it will run form validation, then attach form to email, not giving user chance to fix errors.

I'm good with VB and I would set the validation function to a True/False and use some If statement, but can't seem to find the Java answer, again, I'm lost in the syntax/rules of Java.

Thanks again for your input.
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi stonesrock,

Java and JavaScript are not the same thing- Acrobat uses JavaScript. Do you have the Acrobat JavaScript Reference? Do you have a good Core JavaScript Reference? The Acrobat JS reference is free to download from the Adobe web site (http://www.adobe.com/devnet/acrobat/javascript.php
) and we like Dave Flanagans JavaScript the Definitive Guide by Oreilly for Core JS basics.

Hope this helps,

Dimitri
WindJack Solutions
www.pdfscripting.com
www.windjack.com
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
In you validation function, the script should return either a logical true value of or a logical false value. And if this is the case then you can use a simple 'if' statement to test the returned value and branch accordingly.
// test for a valid formif( controller.validateForm(1) ) {// block of code to execute if result of validation is true//Variables to be used in the mail contextvar rFirstName = resolveNode("root.P1.subfrm_AllSubs.subFrm_GeneralInfo.DataEntryFirstName").rawValuevar rLastName = resolveNode("root.P1.subfrm_AllSubs.subFrm_GeneralInfo.DataEntryLastName").rawValuevar myDoc = event.target;var address = "<span class="spamspan"><span class="u">AnEmail</span> [at] <span class="d">something [dot] com</span></span>";var subject = "Form Submission from " + rFirstName + " " + rLastName;var msgBody = "Form Name. "; {//Send mail actionmyDoc.mailDoc({bUI: false,cTo: address,cSubject: subject,cMsg: msgBody,cSubmitAs: "PDF"});}// end of true action} else {// validation returned false or not true// error message could go here} // end of else or false result

George Kaiser

stonesrock
Registered: Feb 27 2007
Posts: 54
Still missing something, thanks all for dealing with me being stuck on this. Here is a breakdown:

This is the form validation javascript:

function validateForm(showMsg){
vMsg = "";

//validate all required text fields and dropdown lists
for (var nPageCount=0; nPageCount0) {
vMsg += "are required";
vMsg = "Please fill in the required fields that are highlighted in yellow."
xfa.host.messageBox(vMsg);
return false
}
return true;
}

I call the function on a click event doing this following:

controller.validateForm(1)

Setting to one on this call shows message box, a 0 will not show message box.

Just trying to figure out how to pass True/False value from function call, then based on that, I can then go through my email process using If Else statement.

Thanks again all for dealing with my idiot question.