Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Complicated Submit Button: Lock, Hide, Verify, Email and Reverse

New Here ,
May 25, 2017 May 25, 2017

I have a submit button on an Acrobat Form (originated from InDesign). The submit button currently has three different scrips on the same action that perform as follows :

SCRIPT 1

  1. Locks all fields
  2. hides 3 buttons

SCRIPT 2

  1. Verifies required fields are filled in correctly if true then
  2. attaches a pdf to an email with specified field data in the subject and body
  3. If false then returns an alert box for each missing field

    SCRIPT 3

    1. unhides 3 buttons
    2. unlocks all fields

    This allows the user to generate a copy of the form that does not look like a form for the end viewer. Currently, the button coding works.

    I would like to improve the UI and consolidate my alert messages into one, but I can't seem to make it work. Below is the code for Script 2.

    var ok = true;

    var i = 0;

    for (i = 0; i < this.numFields; i++){

    try{

    var f = this.getField(this.getNthFieldName(i));

    if(f.required==true){

    if(f.value==""){

      ok=false;app.alert('Missing Value: '+f.name);

    }

    }

    }catch(ex){};

    };

    if(ok==true){

    // This is the form return email. It's hardcoded

    // so that the form is always returned to the same address.

    // Change address on your form to match the code below

    var cToAddr = "user@email.com"

    var Owner = this.getField("Owner").value;

    var SerialNumber = this.getField("SerialComplete").value;

    // Set the subject and body text for the email message

    var cSubLine = "Report: "  Owner + "

    var cBody = "Report Attached. Serial Number: " + SerialNumber

    // Send the entire PDF as a file attachment on an email

    this.mailDoc({bUI: true, cTo: cToAddr, cSubject: cSubLine, cMsg: cBody});

    };

    TOPICS
    PDF forms
    1.9K
    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    1 ACCEPTED SOLUTION
    Enthusiast ,
    May 26, 2017 May 26, 2017

    Sorry, try this...

    var ok = true;   

    var i = 0;

    var flds = "";

    for (i = 0; i < this.numFields; i++){   

      var f = this.getField(this.getNthFieldName(i));   

    try{

      if(f.required==true){

    if(f.value==""){   

      ok=false;

    if (flds == ""){

      flds = flds + f.name;

    }else{

      flds = flds + "," + f.name;

    }

    };

    };

    }catch(e){

    //app.alert(f.name + " " + e.description);

    }

    };

    if(ok==true){      

    var cToAddr = "user@email.com";

    var url = "mailto:" + cToAddr + "?subject=Report: " +  encodeURIComponent(this.getField("Owner").value) + "&body=Report Attached. Serial Number: " +  encodeURIComponent(this.getField("SerialComplete").value) + "&cc=&bcc=";

    var submitAs = "PDF";//PDF,FDF,XFDF,XDP,XML

    this.submitForm({cURL:url,cSubmitAs:submitAs}); 

    }else{

    app.alert('Missing Values: ' + flds);   

    };

    View solution in original post

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    Community Expert ,
    May 25, 2017 May 25, 2017

    There's not much you can do to change the built-in UI, and I don't see which messages you want to merge... Please provide more details.

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    New Here ,
    May 25, 2017 May 25, 2017

    Currently, for every field that is not filled in an Alert message pops up saying "Missing Value: [field name." This loops through something like 15 required fields. The end user can get an error message for every single missing field, having them push the ok button for each, just for another one to pop up. It's rather cumbersome.

    I think what would work better, is in the if loop, to have an output field that you simple add the field to, then after it finished looping, if the output field is empty, no error message. If it contains information, to put up one error message with all the missing fields.

    Something like the following... but I can't seem to get the code to work.

    var output = "";

    var ok = true;

    var i = 0;

    for (i = 0; i < this.numFields; i++){

    try{

    var f = this.getField(this.getNthFieldName(i));

    if(f.required==true){

    if(f.value==""){

      ok=false;

      output += f.name + ", ";

    }

    }

    }

    if output != ""{

    app.alert('The following fields are required and must be filled in prior to submitting form: ' + output);

    catch(ex){};

    };

    if(ok==true){

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    Community Expert ,
    May 25, 2017 May 25, 2017

    I recommend you remove the try-catch clauses, so you could see what's wrong with your code... Your approach is correct, though.

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    Enthusiast ,
    May 26, 2017 May 26, 2017

    Sorry, try this...

    var ok = true;   

    var i = 0;

    var flds = "";

    for (i = 0; i < this.numFields; i++){   

      var f = this.getField(this.getNthFieldName(i));   

    try{

      if(f.required==true){

    if(f.value==""){   

      ok=false;

    if (flds == ""){

      flds = flds + f.name;

    }else{

      flds = flds + "," + f.name;

    }

    };

    };

    }catch(e){

    //app.alert(f.name + " " + e.description);

    }

    };

    if(ok==true){      

    var cToAddr = "user@email.com";

    var url = "mailto:" + cToAddr + "?subject=Report: " +  encodeURIComponent(this.getField("Owner").value) + "&body=Report Attached. Serial Number: " +  encodeURIComponent(this.getField("SerialComplete").value) + "&cc=&bcc=";

    var submitAs = "PDF";//PDF,FDF,XFDF,XDP,XML

    this.submitForm({cURL:url,cSubmitAs:submitAs}); 

    }else{

    app.alert('Missing Values: ' + flds);   

    };

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    Enthusiast ,
    May 26, 2017 May 26, 2017

    Try this:

    var ok = true; 

    var i = 0; 

    for (i = 0; i < this.numFields; i++){ 

    try{ 

    var f = this.getField(this.getNthFieldName(i)); 

    if(f.required==true){ 

    if(f.value==""){ 

      ok=false;app.alert('Missing Value: '+f.name); 

    }catch(ex){

    app.alert("error(1):" + ex.description);

    }; 

    }; 

    if(ok==true){ 

     

    try{

    // This is the form return email. It's hardcoded 

    // so that the form is always returned to the same address. 

    // Change address on your form to match the code below 

    var cToAddr = "user@email.com​"; 

     

    //Place this script in the buttons mouseUp JavaScript event 

    //http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf#page=345 

    //SUBMIT PDF FORMAT WITH ADOBE READER 

    var url = "mailto:" + cToAddr + "?subject=Report: " +  encodeURIComponent(this.getField("Owner").value) + "&body=Report Attached. Serial Number: " +  encodeURIComponent(this.getField("SerialComplete").value) + "&cc=&bcc="; 

    var submitAs = "PDF";//PDF,FDF,XFDF,XDP,XML 

    this.submitForm({cURL:url,cSubmitAs:submitAs});

    }catch(ex){

    app.alert("error(2):" + ex.description);

    };

    }; 

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    Community Expert ,
    May 26, 2017 May 26, 2017

    How is that code any better? It will still show a separate error message for each field, which is what OP wanted to avoid...

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    Community Expert ,
    May 26, 2017 May 26, 2017

    This script put red strokes to all required fields that are empty, you can easily add an (only one) alert.

    var emptyTest = /^\s*$/;

      for(var i=0;i<this.numFields;i++) {

      var nameField = this.getNthFieldName(i);

      var fld = this.getField(nameField);

            if(fld.type=="text") {

                if(fld.required) {

                    if(emptyTest.test(fld.value)) {

                        fld.strokeColor = rougeCorporate;

                        }

                    }

                }

            }

    And I also put this script in all required text fields, in the "On blur" event:

    event.target.strokeColor = color.transparent;


    Acrobate du PDF, InDesigner et Photoshopographe
    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    New Here ,
    May 30, 2017 May 30, 2017

    Thanks for all your help. I've actually utilized both pieces of script from NKOWA555 and JR_Boulay. I'm hoping I could get one more piece of advice. The alert message is reporting correctly, and that's great.

    However, I realize that my field names are not particularly user friendly. Some of them utilize parent fields for other functions, and many are without spaces. I thought if I could output the tooltip instead, this could be a way around it. I found "username" references the tooltip, but can't seem to make it work. The error message come back with "undefined." Any suggestions how to make that work, or any other ideas?

    Here is the bit of code:

    for (i = 0; i < this.numFields; i++){     

      var f = this.getField(this.getNthFieldName(i));     

    try{ 

      if(f.required==true){ 

    if(f.value==""){     

      ok=false; 

    if (flds == ""){ 

      flds = flds + f.username; 

    }else{   

      flds = flds + ", \n" + f.username; 

    }; 

    }; 

    }catch(e){ 

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    Community Expert ,
    May 30, 2017 May 30, 2017

    The name of this property is "userName", not "username". A small, but crucial, difference.

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    New Here ,
    May 30, 2017 May 30, 2017

    AH YES! Thank you!

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    New Here ,
    Jul 02, 2018 Jul 02, 2018

    Hello -

    I am going through this thread and added the suggestions to my own form.  The question I have on your response, is where do I put that code - in the JavaScript along with the other submit code:  my current code detailed below?

    I like the idea of having the missing required fields highlighted - so the form user can easily scroll through to the areas - as I think that is what your script is doing??

    Sorry for such a newbie question, but this is my first form.

    I appreciate any assistance.

    Thank you

    Keri

    This is the code I have on my 'submit' form button:

    var ok = true;     

    var i = 0;  

    var flds = ""; 

    for (i = 0; i < this.numFields; i++){     

      var f = this.getField(this.getNthFieldName(i));     

    try{ 

      if(f.required==true){ 

    if(f.value==""){     

      ok=false; 

    if (flds == ""){ 

      flds = flds + f.name; 

    }else{ 

      flds = flds + ", " + f.name; 

    }; 

    }; 

    }catch(e){ 

    //app.alert(f.name + "   " + e.description);

    }; 

    if(ok==true){        

    var cToAddr = "support@pennyandroseshop.com"; 

     

    var cSubLine = "Credit Application "

    var cCCAddr = this.getField("ClientEmail").value;

    var cBody = "Thank you for submitting your form.\n" + "We will review your application and get back to you soon."

    this.mailDoc({bUI: true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine, cMsg: cBody});

    var submitAs = "PDF";//PDF,FDF,XFDF,XDP,XML 

    this.submitForm({cURL:url,cSubmitAs:submitAs});   

    }else{ 

    app.alert('The following fields are required and must be filled in prior to submitting the credit application: ' + flds);     

    }; 

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    Community Expert ,
    Jul 03, 2018 Jul 03, 2018

    No, you should only use the script. Remove any other commands you added to the button.

    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines
    New Here ,
    Jul 03, 2018 Jul 03, 2018
    LATEST

    Thank you for replying!

    Sorry I was not clear, I am asking about the script from JR_Boulay:  I am not sure how to incorporate that into my form, do I add the script below to the submit button, and if so not sure how to adjust my existing script (which is included in my previous reply) to include this additional code?

    I appreciate any advice!

    1. var emptyTest = /^\s*$/; 
    2.   for(var i=0;i<this.numFields;i++) { 
    3.   var nameField = this.getNthFieldName(i); 
    4.   var fld = this.getField(nameField); 
    5.         if(fld.type=="text") { 
    6.             if(fld.required) { 
    7.                 if(emptyTest.test(fld.value)) { 
    8.                     fld.strokeColor = rougeCorporate; 
    9.                     } 
    10.                 } 
    11.             } 
    12.         } 
    Translate
    Report
    Community guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    community guidelines