Skip navigation
SpammyNicholas
Currently Being Moderated

LiveCycle Newbie: Validate Before Printing Form

May 5, 2010 10:12 AM

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!

 
Replies
  • Currently Being Moderated
    May 5, 2010 1:46 PM   in reply to SpammyNicholas

    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

     
    |
    Mark as:
  • Currently Being Moderated
    May 6, 2010 5:10 AM   in reply to SpammyNicholas

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 25, 2010 5:12 PM   in reply to DubDubDubDesigns

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

     

    Dave

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 22, 2010 3:37 PM   in reply to djburch

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 23, 2010 8:12 AM   in reply to JRicciuti11

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 4, 2011 2:05 AM   in reply to JRicciuti11

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 4, 2011 10:29 AM   in reply to DubDubDubDesigns

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 5, 2011 2:01 AM   in reply to JRicciuti11

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 22, 2012 9:56 AM   in reply to DubDubDubDesigns

    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!

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 23, 2012 8:22 AM   in reply to milly mac

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 23, 2012 9:40 AM   in reply to DubDubDubDesigns

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

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 23, 2012 7:31 AM   in reply to DubDubDubDesigns

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 23, 2012 10:22 PM   in reply to Argonous

    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/

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 26, 2013 4:50 AM   in reply to SpammyNicholas

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 26, 2013 10:11 AM   in reply to frons79AN

    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/printbuttonActiva tionMethods.pdf

     

    Hope This Helps

     

    Regards

    Graham

    DubDubDubDesigns.co.uk

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 26, 2013 1:12 PM   in reply to DubDubDubDesigns.co.uk

    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!

     
    |
    Mark as:
  • Currently Being Moderated
    May 30, 2013 1:59 PM   in reply to DubDubDubDesigns

    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!

     
    |
    Mark as:
  • Currently Being Moderated
    May 30, 2013 3:40 PM   in reply to jmt9002

    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_validat ion.pdf

     

    Any ???s just ask

     

    Cheers

     

    Graham

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 3, 2013 11:53 AM   in reply to DubDubDubDesigns.co.uk

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

     

    Thanks again!

     

    Joanie

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 3, 2013 11:59 AM   in reply to DubDubDubDesigns.co.uk

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 21, 2013 12:36 PM   in reply to DubDubDubDesigns.co.uk

    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~

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 17, 2013 11:52 AM   in reply to DubDubDubDesigns

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 17, 2013 2:05 PM   in reply to sonerndes

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

     

    http://www.dubdubdubdesigns.co.uk/livecycle/examples/button%20click%20 with%20form%20validation.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

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 17, 2013 2:17 PM   in reply to DubDubDubDesigns.co.uk

    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

    });

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 18, 2013 12:50 AM   in reply to sonerndes

    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.

     

    Re: LiveCycle Newbie: Validate Before Printing Form

     

    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

     

    Re: LiveCycle Newbie: Validate Before Printing Form

     

    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

     

    Re: LiveCycle Newbie: Validate Before Printing Form

     

    Hope this helps.....

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 18, 2013 6:48 AM   in reply to DubDubDubDesigns.co.uk

    Thank you!!

     

    It worked.

     

    You are great.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 21, 2013 2:07 PM   in reply to DubDubDubDesigns.co.uk

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 22, 2013 1:55 AM   in reply to sonerndes

    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();}

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 22, 2013 7:06 AM   in reply to DubDubDubDesigns.co.uk

    Thank you very much.  Worked great.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 23, 2013 12:21 PM   in reply to DubDubDubDesigns.co.uk

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 24, 2013 12:20 AM   in reply to sonerndes

    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();

     

     

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 24, 2013 6:54 AM   in reply to DubDubDubDesigns.co.uk

    Thank you again.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (2)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points