33 Replies Latest reply: Oct 24, 2013 6:54 AM by sonerndes RSS

    LiveCycle Newbie: Validate Before Printing Form

    SpammyNicholas

      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. Re: LiveCycle Newbie: Validate Before Printing Form
          DubDubDubDesigns 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

          • 2. Re: LiveCycle Newbie: Validate Before Printing Form
            SpammyNicholas Community Member

            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_3H 7_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

            • 3. Re: LiveCycle Newbie: Validate Before Printing Form
              DubDubDubDesigns 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

              • 4. Re: LiveCycle Newbie: Validate Before Printing Form
                djburch

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

                 

                Dave

                • 5. Re: LiveCycle Newbie: Validate Before Printing Form
                  JRicciuti11

                  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

                  • 6. Re: LiveCycle Newbie: Validate Before Printing Form
                    DubDubDubDesigns 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.

                    • 7. Re: LiveCycle Newbie: Validate Before Printing Form
                      DubDubDubDesigns 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

                      • 8. Re: LiveCycle Newbie: Validate Before Printing Form
                        JRicciuti11 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

                        • 9. Re: LiveCycle Newbie: Validate Before Printing Form
                          DubDubDubDesigns 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

                          • 10. Re: LiveCycle Newbie: Validate Before Printing Form
                            milly mac

                            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!

                            • 11. Re: LiveCycle Newbie: Validate Before Printing Form
                              DubDubDubDesigns 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

                              • 12. Re: LiveCycle Newbie: Validate Before Printing Form
                                milly mac Community Member

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

                                • 13. Re: LiveCycle Newbie: Validate Before Printing Form
                                  Argonous

                                  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

                                  • 14. Re: LiveCycle Newbie: Validate Before Printing Form
                                    radzmar Community Member

                                    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/

                                    • 15. Re: LiveCycle Newbie: Validate Before Printing Form
                                      frons79AN

                                      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?

                                      • 16. Re: LiveCycle Newbie: Validate Before Printing Form
                                        DubDubDubDesigns.co.uk

                                        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

                                        • 17. Re: LiveCycle Newbie: Validate Before Printing Form
                                          frons79AN 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!

                                          • 18. Re: LiveCycle Newbie: Validate Before Printing Form
                                            jmt9002

                                            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!

                                            • 19. Re: LiveCycle Newbie: Validate Before Printing Form
                                              DubDubDubDesigns.co.uk Community Member

                                              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

                                              • 20. Re: LiveCycle Newbie: Validate Before Printing Form
                                                jmt9002 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

                                                • 21. Re: LiveCycle Newbie: Validate Before Printing Form
                                                  jmt9002 Community Member

                                                  Hi Graham,

                                                   

                                                  One more question, now that I have the form working. Is there a way for me to edit the error message that appears if some of the required fields have been left blank?

                                                   

                                                  Thanks,

                                                  Joanie

                                                  • 22. Re: LiveCycle Newbie: Validate Before Printing Form
                                                    milly mac Community Member

                                                    Graham,

                                                     

                                                    This script has worked well for me in the past, but now I have a checkbox (hirebox) that when checked, pops up another field (hiredate) which must be filled before printing will be allowed.  Here's the script I have applied to the Print button:

                                                     

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

                                                     

                                                    if((hirebox.rawValue == 1) & (startdate.rawValue == null)){

                                                                    xfa.host.messageBox("Oh-sorry!  You must enter a start date at the top of this form to be able to print.")}

                                                    else{

                                                                    PrintButton1.execEvent("click")}

                                                     

                                                    The problem I have now is that the Print button doesn't work otherwise (as in when it is not necessary to check the "hirebox" checkbox).

                                                     

                                                    Oh, and you may need to know also, here's the script I have applied to "hirebox":

                                                     

                                                    form1.#subform[0].hirebox::change - (JavaScript, client)

                                                     

                                                    if

                                                    (hirebox.rawValue==1)

                                                        {startdate.presence = "visible"}

                                                    else

                                                        {startdate.presence = "hidden"}

                                                     

                                                     

                                                    Where have I gone wrong?

                                                     

                                                    As always, thanks~

                                                    • 23. Re: LiveCycle Newbie: Validate Before Printing Form
                                                      sonerndes Community Member

                                                      I have made a dynamic submit button which works great for what i need but using this submit button doesn't validate my required fields.

                                                       

                                                      This is the script i have used in mouseup event, using javascript

                                                      var cToAddr = "909@gideons.org";

                                                      var cCCAddr = RegionalDirector.rawValue;

                                                      var cSubLine = "909 Camp Visitation Report-" + xfa.resolveNode("#subform[0].#subform[7].Country").rawValue; var cBody = "Thank you for submitting your 909 report.\n" + "Save a copy for your records";

                                                      event.target.mailDoc({

                                                                bUI: true,

                                                                cTo: cToAddr,

                                                                cCc: cCCAddr,

                                                                cSubject: cSubLine,

                                                                cMsg: cBody

                                                      });

                                                       

                                                       

                                                      Is it possible to script this button to check required fields and show a message box like you did for the print form button above?

                                                       

                                                      Thanks

                                                      • 24. Re: LiveCycle Newbie: Validate Before Printing Form
                                                        DubDubDubDesigns.co.uk Community Member

                                                        I have created an example which I have posted on the below link

                                                         

                                                        http://www.dubdubdubdesigns.co.uk/livecycle/examples/button%20click%20with%20form%20valida tion.pdf

                                                         

                                                        Its quite simple-

                                                        - set the fields on your form as user entered - required fields,

                                                        - set up your required fields form actions in the form properties section.

                                                        - surround your script with a if (form1.execValidation()) { YOUR SCRIPT

                                                        GOES HERE }

                                                         

                                                        Any problems let me know

                                                        • 25. Re: LiveCycle Newbie: Validate Before Printing Form
                                                          sonerndes Community Member

                                                          Thank you for replying.

                                                           

                                                          Do if put this script on my submit button?

                                                           

                                                          I am very new at this and don’t understand it all so please bear with me?

                                                           

                                                           

                                                          Would it look like this?

                                                           

                                                          if (myfield.execValidation())

                                                          {

                                                          var cToAddr = "909@gideons.org";

                                                          var cCCAddr = RegionalDirector.rawValue;

                                                          var cSubLine = "909 Camp Visitation Report-" + xfa.resolveNode("#subform[0].#subform[7].Country").rawValue; var cBody = "Thank you for submitting your 909 report.\n" + "Save a copy for your records";

                                                          event.target.mailDoc({

                                                              bUI: true,

                                                              cTo: cToAddr,

                                                              cCc: cCCAddr,

                                                              cSubject: cSubLine,

                                                              cMsg: cBody

                                                          });

                                                          • 26. Re: LiveCycle Newbie: Validate Before Printing Form
                                                            DubDubDubDesigns.co.uk Community Member

                                                            Hi

                                                             

                                                            No Problem, we all have to start somewhere.

                                                             

                                                            Yes you would just wrap your existing code in the "if" statement as you

                                                            have shown.  However, its not so much myfield but the entire form you are

                                                            performing the execValidation code on (by default the entire form is called

                                                            form1 e.g. form1.execValidation()), you can see this name at the top of the

                                                            tree structure in the hierarchical view within Livecycle.

                                                             

                                                            image: Inline images 1

                                                             

                                                            Don't forget you also need to set any fields you wish to be mandatory as a

                                                            required field in the Object View, Value Tab

                                                             

                                                            image: Inline images 2

                                                             

                                                            One final thing to configure is the Form Validation settings in the Form

                                                            Validation Tab in the form properties. Here you can configure the form

                                                            validation responses to invalid forms. Set this to your own preference.

                                                             

                                                            You access form properties via menu File-> Form Properties

                                                             

                                                            image: Inline images 3

                                                             

                                                            Hope this helps.....

                                                            • 27. Re: LiveCycle Newbie: Validate Before Printing Form
                                                              sonerndes Community Member

                                                              Thank you!!

                                                               

                                                              It worked.

                                                               

                                                              You are great.

                                                              • 28. Re: LiveCycle Newbie: Validate Before Printing Form
                                                                sonerndes Community Member

                                                                You helped me greatly last week and was wondering if you could help me with another question or point me in the right direction.

                                                                My submit button works and the validation formula you gave me.

                                                                 

                                                                But I have another email address that I would like to be copied and not sure how to script it.  I have a field that will be populated with the email address only if other fields are filled out.

                                                                 

                                                                So this email address will not always be populated.

                                                                 

                                                                How to add this to my script.

                                                                 

                                                                For a reminder here is my script.

                                                                 

                                                                if (form1.execValidate())

                                                                {var cToAddr = "909@gideons.org";

                                                                var cCCAddr = RegionalDirector.rawValue

                                                                var cSubLine = xfa.resolveNode("#subform[0].#subform[7].CampName").rawValue + ", " + xfa.resolveNode("#subform[0].#subform[7].Country").rawValue + " 909 Camp Visitation Report"; var cBody = "Thank you for submitting your 909 report.\n" + "Save a copy for your records";

                                                                event.target.mailDoc({

                                                                    bUI: true,

                                                                    cTo: cToAddr,

                                                                    cCc: cCCAddr,

                                                                    cSubject: cSubLine,

                                                                    cMsg: cBody

                                                                });}

                                                                 

                                                                 

                                                                Thank you in advance.

                                                                • 29. Re: LiveCycle Newbie: Validate Before Printing Form
                                                                  DubDubDubDesigns.co.uk Community Member

                                                                  The code to add if an email exists is in red. The cc address field used a

                                                                  semicolon separated list of email addresses, so you can add as many as you

                                                                  wish using semicolon between each.

                                                                   

                                                                  if (form1.execValidate())

                                                                   

                                                                  {var cToAddr = "909@gideons.org";

                                                                   

                                                                  var cCCAddr = RegionalDirector.rawValue

                                                                   

                                                                  if (otheremailfield.rawValue != null)

                                                                   

                                                                  {

                                                                   

                                                                  cCCAddr += ";" + otheremailfield.rawValue;

                                                                   

                                                                  }

                                                                   

                                                                  var cSubLine = xfa.resolveNode("#subform[0].#subform[7].CampName").rawValue

                                                                  + ", " + xfa.resolveNode("#subform[0].#subform[7].Country").rawValue + "

                                                                  909 Camp Visitation Report"; var cBody = "Thank you for submitting your 909

                                                                  report.\n" + "Save a copy for your records";

                                                                   

                                                                  event.target.mailDoc();}

                                                                  • 30. Re: LiveCycle Newbie: Validate Before Printing Form
                                                                    sonerndes Community Member

                                                                    Thank you very much.  Worked great.

                                                                    • 31. Re: LiveCycle Newbie: Validate Before Printing Form
                                                                      sonerndes Community Member

                                                                      Is it possible to add another cc using the code if an email exist?

                                                                       

                                                                      If so, where do I put it with in the bracket?

                                                                       

                                                                      Thanks again.

                                                                      • 32. Re: LiveCycle Newbie: Validate Before Printing Form
                                                                        DubDubDubDesigns.co.uk Community Member

                                                                        Hi, you just copy the if statement again below the other and rename the

                                                                        field to look at.

                                                                         

                                                                        if (form1.execValidate())

                                                                         

                                                                        {

                                                                         

                                                                        var cToAddr = "909@gideons.org";

                                                                         

                                                                        var cCCAddr = RegionalDirector.rawValue

                                                                         

                                                                        if (otheremailfield.rawValue != null)

                                                                         

                                                                        {

                                                                         

                                                                        cCCAddr += ";" + otheremailfield.rawValue;

                                                                         

                                                                        }

                                                                         

                                                                        if (otheremailfield2.rawValue != null)

                                                                         

                                                                        {

                                                                         

                                                                        cCCAddr += ";" + otheremailfield2.rawValue;

                                                                         

                                                                        }

                                                                         

                                                                        var cSubLine = xfa.resolveNode("#subform[0].#subform[7].CampName").rawValue

                                                                         

                                                                        + ", " + xfa.resolveNode("#subform[0].#subform[7].Country").rawValue + "

                                                                         

                                                                        909 Camp Visitation Report"; var cBody = "Thank you for submitting your 909

                                                                         

                                                                        report.\n" + "Save a copy for your records";

                                                                         

                                                                        event.target.mailDoc();