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

Need validation script to make Submit Form work

bensimmons99
Registered: Jun 2 2010
Posts: 28
Answered

I have 6 fields that are required, below is the email function that i have scripted into a button to submit. What type of script would I use to make the below code dependant upon all 6 required fields having some data in them? Please advise:

Also, is there anyway to have this code submit the form as a PDF instead of an FDF?

{
// This is the form return e-mail. Its hardcoded
// so that the form is always returned to the same address
var cToAddr = "nightvision [dot] procurement [at] itt [dot] com";

// First, get the client CC e-mail address
var cCCAddr = this.getField("DELIVER_TO").value;

var cSubLine = "NEW PR SUBMITTED ( "
+ this.getField("TOTAL").value + " "
+this.getField("PRODUCT OR SERVICE").value + " "
+ this.getField("CURRENTDATE").value + ")";
var cBody = "Thank you for submitting your form.\n" +
"Save the mail attachment for your own records";

// Send the form data as an FDF attachment on an e-mail
this.mailForm({bUI: true, cTo: cToAddr, cCc: cCCAddr,
cSubject: cSubLine, cMsg: cBody});
}

try67
Expert
Registered: Oct 30 2008
Posts: 2399
You need to add something like this before the block of code you already have:

if (this.getField("field1").value !=null && this.getField("field1").value!="" && this.getField("field2").value !=null && this.getField("field2").value!="" && this.getField("field3").value !=null && this.getField("field3").value!="" && this.getField("field4").value !=null && this.getField("field4").value!="" && this.getField("field5").value !=null && this.getField("field5").value!="" && this.getField("field6").value !=null && this.getField("field6").value!="")  // change the names of the fields to match your fields...{// the code that sends the email goes here}

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

bensimmons99
Registered: Jun 2 2010
Posts: 28
Thanks! That Worked Great!

Here is the final code. Currently if some required form is missing data it just stops the send email command.

Where, and what code would I put to place a general alert "You cannot submit form until all fields are completed"

//Validate before continuing
if (this.getField("DELIVER_TO").value !=null && this.getField("DELIVER_TO").value!="" && this.getField("PN#1").value !=null && this.getField("PN#1").value!="" && this.getField("DESCRIPTION1").value !=null && this.getField("DESCRIPTION1").value!="" && this.getField("PRICE1").value !=null && this.getField("PRICE1").value!="" &&
this.getField("DATE REQUIRED1").value !=null &&
this.getField("DATE REQUIRED1").value!="" && this.getField("ACCOUNT NUMBER1").value !=null && this.getField("ACCOUNT NUMBER1").value!="")
// change the names of the fields to match your fields...
{
// This is the form return e-mail. Its hardcoded
// so that the form is always returned to the same address
var cToAddr = "nightvision [dot] procurement [at] itt [dot] com";// First, get the client CC e-mail address
var cCCAddr = this.getField("DELIVER_TO").value;

var cSubLine = "NEW PR SUBMITTED ( "
+ this.getField("TOTAL").value + " "
+this.getField("PRODUCT OR SERVICE").value + " "
+ this.getField("REQUEST RECEIVED").value + ")";
var cBody = "Thank you for submitting your form.\n" +
"Save the mail attachment for your own records";

// Send the form data as an FDF attachment on an e-mail
this.mailForm({bUI: true, cTo: cToAddr, cCc: cCCAddr,
cSubject: cSubLine, cMsg: cBody});
}
try67
Expert
Registered: Oct 30 2008
Posts: 2399
Add this just after the block of code that sends the email:
else {app.alert("You cannot submit form until all fields are completed");}

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com