Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

LiveCycle Newbie: Validate Before Printing Form

Avatar

Level 1

I have a form created in Adobe Acrobat Pro that I have brought into LiveCycle to add print and emails buttons to. However, I need a specific functionality added to the standard "Print" button. It is a legal form that has required fields and the client needs to fill in all the required fields on the form BEFORE printing and signing it. We have had problems in the past with clients not filling in all the required fields before sending it back to them. So, I need to somehow make the print button check to make sure all the required fields are filled in and send a warning message and/or prevent printing if all the required fields are not filled in. Is there a way to do this?

I am using LiveCycle Designer ES 8.2 and I am VERY new to this program so the simpler the solution the better.

Thanks in advance for the help!

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Hi

I have now created a form for this example as the best way to explain to people.

You are correct you can do it within the same button (my knowledge and skills have developed somewhat since the orignal post)

Here is a link to the page where the example can be found.

http://www.dubdubdubdesigns.co.uk/livecycle/formprinting.html

If you have any questions just ask

Regards

Graahm

View solution in original post

33 Replies

Avatar

Former Community Member

Hi

I would add another fake print button over the top of the existing one but just add a standard button not a print button.

then to the click scripting event in the script editor add something like the below

if ((TextField1.rawValue == null) or (TextField2.rawValue == null) & (CheckBox1.rawValue == "1")) then

xfa.host.messageBox("You must enter the required data to be able to print this form")

else

PrintButton1.execEvent("click")

endif

as you are relatively new to this. Incase the above it giberish to you I will try to explain what the above is doing.

the above is an if statement using formcalc (which is the default on button objects)

as this code is inserted in to the click event  (you can see what event you are looking from the dropdown at the top left of the script editor window.... make sure click is selected, and formcalc is set in the drop down to the right of the script editor window.

each bracketed command e.g. (TextField1.rawValue == null) is address a single field in your form. You will need to make sure you adjust these names and the path to these names so it may end up looking like (Form1.subform.TextField1.rawValue == null).

A quick tip to ensure you have the right path is with the cursor in the script window move your mouse over the field you wish to address, hold Ctrl button and click the field. This will load the field path in to the script editor and all you have to add is the .rawValue portion of the command.

You require '==' because means 'is equals to' in formcalc

the null term means 'if the field is empty'

if you have checkboxes that require to be ticked you must address them and look for a value of 1 (as in the example) as as default when a checkbox is selected it has a value of 1.

you can use or commands or & commands between expressions.

please note all the comments together require brackets round them hence the double brackets at the start and end of the expression.

once you have added all the required expressions to the top line

the second line is saying if the statement returns a true value  e.g. in our example a true value would be returned if TextField1 or TextField2 empty AND the checkBox1 is not ticked

then this will pop up a message box saying you have not entered the required fields to print this form

then the else statement says to click the print button for the user.... which will print the form as the print button does now.

I know it may seem complicated but it honestly is not that difficult.

Feel free to come back to me if you need any further help.

Regards

Graham

Avatar

Level 1

Hi Graham,

I tried what you said and when I run it through Adobe Reader it gives me a message that says the script has failed. Wat I did was copy and paste the information you gave me and changed the form field names in the script as suggested. I made sure that it was in Form Calc and set to client. I also made sure that the event was set on click. This is what was in the script editor when I saved it and tested it in Reader:

topmostSubform.Page10.Button_3::click - (FormCalc, client)
if ((Page1.BETWEEN_ASIGRA_Inc_1120_Finch_Avenue_West_Suite_400_Toronto_Ontario_Canada_M3J_3H7_ASIGRA_Service_Provider_Company_Name_Address_AND.rawValue == null) or (Sign_Above_This_Line.rawValue == null) or (Sign_Above_This_Line_2.rawValue == null) or (Print_Name.rawValue == null) or (Title.rawValue == null) or (Date_2.rawValue == null) &  (Date.rawValue == "1")) then
xfa.host.messageBox("You must enter the required data to be able to print this form")
else
PrintButton1.execEvent("click")
endif

You've been incredibly helpful so far so I hope you can help me figure this out all the way through.

Much thanks!

Spammy

Avatar

Former Community Member

Hi There

If you want to send me your form  I will take a look at the code, as it is

difficult to see any issue without the fields there etc.

email it to washydraulics@hotmail.co.uk

If you have any questions please don't hesitate to contact me.

Kind Regards

Graham Spaull

Avatar

Former Community Member

Great tip, Graham.  I'm using your script to accomplish the same objective.  Works like a charm.

Dave

Avatar

Former Community Member

Hi,

I am trying to set my pdf form to not print unless all require fields are filled out, but I am having no such success.  I've tired what is listed above, but was unable to get it to work.

Your help would be greatly appreciated!

Jen

Avatar

Former Community Member

I will be out of the office starting 22/12/2010 and will not return until

04/01/2011.

Our offices are closed between Christmas and New Year. Have a Merry Christmas

and a Happy New Year.

Avatar

Former Community Member

Hi Jen

I would try something simple in the print button such as:

if (form1.execValidate()){

xfa.host.print(1, "0", (xfa.host.numPages -1).toString(), 0, 0, 0, 0, 0);

}

Then set all the fields you need filling out as required fields.

Hope this helps

Graham

Avatar

Former Community Member

Thanks Graham. I have added the script recommended and the print button is now not working at all. Any other suggestion? Your help is greatly appreciated!

Thanks you,

Jen Ricciuti |  Coordinator, Safety Services

(403) 234-6296 (| jennifer.ricciuti@sjrb.ca

ACCOUNTABLE    BALANCE    CUSTOMER FOCUSED    INTEGRITY    LOYALTY    POSITIVE, CAN DO ATTITUDE    TEAM PLAYER

Avatar

Former Community Member

Hi Jen

It may be easier to send me the form.

gspaull@moog.com

Please include in your email the field you wish to be mandatory.

...... one last thing to make sure before you send the form, make sure the

script language for the script I gave you yesterday is set to Javascript,

and the form is set to a dynamic form

Regards

Graham

Avatar

Level 3

Graham,

I've only got 1 area, a drop down box, that is required.  I think I've got the script correct (preferences are set to Formcalc and dynamic, formcalc is selected in the scripting area of the form)

 

TopmostSubform.Page1.PrintButton1::click - (FormCalc, client)

xfa.host.print(1, "0", (xfa.host.numPages -1).toString(), 0, 0, 0, 0, 0);

if (DropDownList1.rawValue == null) then

xfa.host.messageBox("You must choose an academic area to be able to print this form")

else

PrintButton1.execEvent("click")

endif

But it doesn't work.  I wonder . . . why did you suggest WAAAYYY up to (5/5/2010) that another button be placed on top of the print button.  I didn't do this because I just don't get why the script can't be applied to the standard print button.  I guess this is my problem.  Can you explain why the extra button and/or, do you see any reason in the above script why it shouldn't work?

Thanks!

Avatar

Correct answer by
Former Community Member

Hi

I have now created a form for this example as the best way to explain to people.

You are correct you can do it within the same button (my knowledge and skills have developed somewhat since the orignal post)

Here is a link to the page where the example can be found.

http://www.dubdubdubdesigns.co.uk/livecycle/formprinting.html

If you have any questions just ask

Regards

Graahm

Avatar

Level 3

Great! Thanks so much, I really appreciate your help with this!

Avatar

Level 1

Graahm,

Thanks for your example.  It has helped me tremendously!

I do have a question though.  How would you use method 1 to Validate more than one field.  I have a document that has multiple fields that need to be validate before printing ans am not quite sure how to apply yor code to this.

Thanks for you help!

Shane

Avatar

Level 10

Hi,

check this article.

It explains to prevent printing a form when any mandatory field is empty.

http://forms.stefcameron.com/2008/04/13/prevent-printing-pdf-forms-in-acrobat-8/

Avatar

Former Community Member

I haved a similar problem, but with a checkbox which I think is a little trickier.

Is there a way to:

  1. set a print button access as readOnly by default?
  2. change it as the checkboxA gets flagged (and make it readOnly again should it get deflagged)?

I tried various solutions but the closest to an acceptable one is that I get the printbutton locked on readOnly ONLY after an initial flagging/deflagging of the checkbox: so if the form is left blank, I'm still able to print through the printbutton, which is what I'd like to prevent user from.

Any working help?

Avatar

Level 1

Hi

There are a few ways to do this.

You can do it on the click activity of the button itself to check if the checkbox is ticked e.g.

form1.#subform[0].PrintButton1::click - (JavaScript, client)

if ( CheckBox1.rawValue == "1" )

{

xfa.host.print(1, "0", (xfa.host.numPages -1).toString(), 0, 0, 0, 0, 0);

}

else

{

xfa.host.messageBox("You Must Check The Box To Print This Form");

}

Or you can set the print button as readOnly when it is initialised

form1.#subform[0].PrintButton1::initialize - (JavaScript, client)

this.access = "readOnly";


Then use the mouseUp event on the checkbox to check its value and set the button to active if its checked.

form1.#subform[0].CheckBox1::mouseUp - (JavaScript, client)

if (this.rawValue == "1")

{

PrintButton1.access = "open";

}

else

{

PrintButton1.access = "readOnly";

}


Or you could simply set the print button's visibility to Invisible as default and have the checkbox change the presence of the button if it is checked.

form1.#subform[0].CheckBox1::mouseUp - (JavaScript, client)

if (this.rawValue == "1")

{

PrintButton1.presence = "visible";

}

else

{

PrintButton1.presence = "hidden";

}

I have uploaded an example of all 3 methods in a single form here

http://www.dubdubdubdesigns.co.uk/livecycle/examples/printbuttonActivationMethods.pdf

Hope This Helps

Regards

Graham

DubDubDubDesigns.co.uk

Avatar

Former Community Member

I'm an idiot: that was almost the same code I already had but of course it wasn't working because I mistyped the Javascript, a very rookie-like error:

this.access == "readOnly";


Of course it wasn't working...

Anyway thank you Graham, I found very interesting the three way methods you submitted!

Avatar

Former Community Member

Hi Graham,

I've used your above example on my form and it works great. I do have a couple questions though.

1. Can this be set-up to work on radio buttons?

2. Is there a way to highlight the required fields if they were left blank? My form has many required fields and it would be much more user friendly if I were able to get it highlight the fields that were missed.

Thanks!

Avatar

Level 1

Hi


You may find it easier to implement the method described in the below link on my website.


This prevents printing and highlights any fields that are set as "required by user" that are not complete when an attempt to print is made (including the ctr+P shortcut)

http://www.dubdubdubdesigns.co.uk/livecycle/examples/pre-print_validation.pdf

Any ???s just ask

Cheers

Graham

Avatar

Former Community Member

Thank you so much Graham! That worked perfectly and was much easier than all the code I put in originally.

Thanks again!

Joanie

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----