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

Validating required data text field and radio buttons on a form before printing or saving

Sharonina
Registered: Dec 12 2011
Posts: 5

HI I am new to adobe acrobat, I am creating a form with a bunch of required text fields, radio button and check boxes. I would like to know if anyone can help me fins a way of making sure all the required fields are entered before i allow them to print & save?
 
I tried to use the validate field ()* on the print button but nothing works.
 
I tried using the script:f = getField(event.target.name)
if (f.value.length == 0)
{
//Optional Message - Comment out the next line to remove
app.alert("This field is required. Please enter a value.")
f.setFocus()
} to validate each individual field but it does not work on the radio button and on the text field it locks up.. i ahd to go to the task manager and shut down the program.
 
Please help as this is the final piece to complete my form.

try67
Expert
Registered: Oct 30 2008
Posts: 2398
First of all, if the user saves or prints the file using the built-in buttons, there's nothing you can do to prevent it. You can display an error message, or even reset the form, but that could be extremely annoying to the user.

What you need to do is to loop over all of the fields, chceking which ones are required and if so, if they have a value (note that different field types have different "empty" values), and if so, show a message and abort the operation. I posted a generic function that does this a while ago. If you want, I can look it up.

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

Jamesone
Registered: Jul 31 2011
Posts: 15
Here is another way of doing this which I found off the net and works well. Hope this helps someone, this is not my code....

Make a Print button on the form and add this to javascript action for print button.
validateFields();

GOTO Tools, document javascripts and add the following to a new script.

//-------------------------------------------------------------
//-----------------Do not edit the XML tags--------------------
//-------------------------------------------------------------

//
//validateFields
//
/*********** belongs to: Document-Level:validateFields ***********/
function validateFields()
{


//a counter for the number of empty fields
var flg = 0

// count all the form fields
var n = this.numFields

//create an array to contain the names of required fields
//if they are determined to be empty

var fArr = new Array();

//loop through all fields and check for those that are required
// all fields that have a '*' in their tool tip are required

for(var i = 0;i0){
app.alert('There are '+flg+' fields that require a value\n\n'+ fArr,3)
}
else{
this.print();
}

}
//
////
//print2:Annot1:MouseUp:Action1
//
/*********** belongs to: AcroForm:print2:Annot1:MouseUp:Action1 ***********/
validateFields();
//
//After doing this goto the Txt fields you want to be reminded to fill in and in the tooltip section place a * after any text you enter.

When you press the print button and the form is not filled in where you have placed the * in the tooltip a popup will come up telling you to fill in missing fields.
It will not print with the button until the form has been corrected.

The only problem I have found with this. Is that 0 is not a value and will ask that a number from 1 onwards needs to be placed in txt field.

Works great for me and will stop people printing forms out without filling them in correctly...





try67
Expert
Registered: Oct 30 2008
Posts: 2398
I would be careful using this code. It doesn't look right to me at all. In fact, it looks like it will cause an endless loop.

Like I said earlier, you can't prevent someone from printing a file if they use the built-in Print command instead of pressing your Print button.

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

Sharonina
Registered: Dec 12 2011
Posts: 5
i have my own print and save button which uses the mouse up action command.. i am new too acrobat and not familiar with javascripting so it is pretty difficult for me to grasp some of the scripting.
Sharonina
Registered: Dec 12 2011
Posts: 5
i have my own print and save button which uses the mouse up action command.. i am new too acrobat and not familiar with javascripting so it is pretty difficult for me to grasp some of the scripting.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Actually, I just created a script that allows you to apply the same kind of validation of the required fields that is done when the form is submitted just before the file is printed or saved. If the file does not meet the required condition, the user will be presented with an error message and the form fields will be printed empty, but they will retain their data and the user could continue editing them.
See here: http://try67.blogspot.com/2011/12/acrobat-validate-fields-before-printing.php

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

Sharonina
Registered: Dec 12 2011
Posts: 5
hey thank you james for the scripst i tried it but it did not work. Try6, my forms are not submitted they are use on site without any internet connection and after filling up each form they will be saved on the drive and one copy will be printed for the client. the forms will be filled by a tech attending to the client. I need to amke sure that the tech fill up teh forms correctly so that we can obtain all crucial information. I checked required on alll data fields and check boxes but i realize that it will only be activated if i use the submit button.
If you could guide me to how to make this work that would be great.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
The script I developed has nothing to do with submitting the file. You can use it to present an error message if someone tried to print or save the file without filling-in all the required fields first, and the printed/saved copy will be blank.

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

Sharonina
Registered: Dec 12 2011
Posts: 5
yes that script would be great. does it indicate which fields need to be filled in correctly or just a general error msg.. That is exactly what i need to make sure the techs fill up everything! Is it possible for you to guide me on how to do this? Thanks a bunch!
try67
Expert
Registered: Oct 30 2008
Posts: 2398
As you can see from the second screenshot, the error message contains the names of all the fields that still need to be filled-in.
When you purchase the script it comes with full instructions on how to install and use it, and in case of any doubts you can always send me an email.

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