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

Help: Validate Text Fields & Radio Buttons - Breakpoint/Syntax Errors

Michael Frommer
Registered: Apr 3 2009
Posts: 80
Answered

I want to:
- validate a AcroForm [b]before[/b] it prints (users would be using File/Print)
- [b]stop[/b] the print if it fails validation
- send an alert message on failure (each validation check sends a different message)
- allow to print if no errors & passes validation

I expect I need to place this script at the 'Doc Will Print' action. Not sure if I got the code right; I'm getting stuck at an 'invalid break' error, and I'm not 100% confident that I didn't make other mistakes in the code.

As always, your time to review this and tell me how to correct is appreciated.

There are 2 groups of fields that need to be validated:
- 1st validation: 5 text fields which all have the same Parent name: "Contact. [i]child[/i]"
- 2nd validation: 1 (group of 5) radio/checkboxes which share the same name: "Payment.Form" (each with their own respective export value)

    var bSuccess=True;
    var emptyTest = /^\s*$/;
    var fieldCount = this.getField("Contact").length;
    var fld = 0;
    var pymtform = this.getField("Payment"); 
for (var i=0; i < fieldCount; i++);
{
    fld = this.getField("Contact");
if(emptyTest.test(fld.value));
    bSuccess=false;{
 
    this.printDoc(false);
    app.alert({cMsg: "REGISTRATION FORM INCOMPLETE\n\n" + "PLEASE INPUT CONTACT INFORMATION", cTitle:"REGISTRATION FORM ERROR"});
    break;{
 
}
    if(bSuccess);
    if (pymtform.value == "Off") {
 
    this.printDoc(false);
    app.alert({cMsg: "REGISTRATION FORM INCOMPLETE\n\n" + "PLEASE SELECT FORM OF PAYMENT\n\n" +"If paying by credit card, please input credit card information requested", cTitle:"REGISTRATION FORM ERROR"});
    break;{
 
    if(bSuccess)
    this.printDoc(true);
}
}

My Product Information:
Acrobat Pro 8.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2399
You have plenty of problems here, some are extremely basic syntax errors (for example, you're putting semi-colons after your if-statements). I, once again, suggest you either learn some JavaScript, or hire a professional to do this for you.

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

Michael Frommer
Registered: Apr 3 2009
Posts: 80
try67,

I appreciate you pointing out the semi-colons. Thanks.

I [i]am[/i] trying to learn. That is one of the reasons I come here with questions. It's not like I am asking anyone on the forum to write code from scratch for me.

Programming is not my job, but I have enough interest in learning, at least the basics, so that I can bring added value in the volunteer service I provide (to a not-for-profit organization) for which no one receives any compensation. So i'm not in a position to hire a professional either.

So i make an attempt at the code and when it fails, I attempt to troubleshoot it myself. Searching this forum, etc., has help me a great deal. When that fails I ask for assistance from those with the experience and knowledge. I come here hoping to receive a friendly response and learn where and why I made a mistake.

If you don't want to show/tell me the specifc errors I made that's your prerogative. But must your response be so condescending? If those with very very little knowledge are not welcome here, let a moderator advise me.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Michael,
For just starting out with programming you have much too much code here. And Try67 has a point, the problems with the code are very basic. I would suggest that you first get a book on Core JavaScript since this is the first set of problems with the code. My favorite is the O'Reilly "JavaScript, The Definitive Guide". You need a handle on basic syntax and programming concepts first.

Then read this article on the console window:

http://www.acrobatusers.com/tutorials/2006/javascript_console

You might also want to look at this blog:

http://www.acrobatusers.com/blogs/thomp/copying-and-pasting-code

If your code has errors during execution, then those errors will be displayed in the console window. But the console window is also the best place to try out scripting ideas. It will be an invaluable tool for learning Acrobat JavaScript. It's best to test out code snippets in small pieces, just to make sure you've got it right. Then put them together after you know the little bits work.

This is also true when asking questions on the forum. You'll get the best answers when you ask about a single, specific, and clearly defined things. Questions that are ambigous, long, and/or complex don't usually get a good response. Remember, we all have to spend our own time answering these questions, no one gets paid for this, so you have to use our time wisely.

Cheers,
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

try67
Expert
Registered: Oct 30 2008
Posts: 2399
Hi Michael,

I don't mean to be "condescending", but your code proves that you're missing some very basic knowledge in programming, which makes it very difficult to help you. It's like if someone wants to perform open heart-surgery without knowing where the heart is...
You've got to start with the basics and build your way up to the more complex stuff. You've received plenty of links and suggestions on how to do it.
And Thom is right. You're much more likely to get help if you post a specific, detailed problem, and not a large piece of code and a general "it's not working"...
Bottom line is I (and others) have helped you before, and we'll be willing to help you again, but you must do your part as well.

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