9 Replies Latest reply on Mar 20, 2014 5:16 PM by lccdg

    Conditional submit button w/ checkboxes

    Erwann R

      Hello,

       

      I am just beggining to use Adobe Acrobat pro, and I am stuck with a conditional submit button issue.

       

      In fact, once I'm done with my form, I want to add a submit button at the bottom.

       

       

      But this would not be a simple "mailto" button, with an email adress corresponding. In fact, what I want my button to do is to send the mail to a specific email adress chosen all the time, and, to add some mailing adress if certain checkboxes are ticked.

       

      To be clearer, there will be like 4-5 checkboxes which will correspond to 4-5 different mailing adresses which are added to the message recipients in the submit button if ticked.

       

      Has anyone an idea of the way to do it?

       

      I have thought about a portion of code to assign to each checkbox a mail adress, but i'm not sure of how to finish the code to get the result desired.

      -----------

       

      btn = document.getElementByID('Button')

      btn.addEventListener('click', function{
                checkbox=doc.getElementbyId('Checkbox')
                val = checkbox.value

                switch val :
                case "doa"
                email = doa@fr.******.com

                case "cco"

                email = cco@fr.*****.com

       

       

      }

      ----------

       

      Can anyone help about this? thank you in advance

        • 1. Re: Conditional submit button w/ checkboxes
          try67 MVP & Adobe Community Professional

          This code will get you no-where. It's written for a web-page, not for a PDF.

           

          A good place to start is this tutorial: http://acrobatusers.com/tutorials/dynamically-setting-submit-e-mail-address

          1 person found this helpful
          • 2. Re: Conditional submit button w/ checkboxes
            Erwann R Level 1

            Thank you Gilad, I'll look up what I can do with this tuto!

            • 3. Re: Conditional submit button w/ checkboxes
              Erwann R Level 1

              I have checked out the tuto that you gave me, which helped me out with this piece of code :

               

              --------

              // 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 = "formsAdmin@BigCorp.com"

               

              // First, get the client CC email address

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

               

              // Now get the beneficiary email only if it is filled out

              var cBenAddr = this.getField("BennyEmail").value;

              if(cBenAddr != "")

              cCCAddr += ";" + cBenAddr;

               

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

              var cSubLine = "Form X-1 returned from client"

              var cBody = "Thank you for submitting your form.\n" + "Save the filled form attachment for your own records"

               

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

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

              ------

               

              So I have an idea to solve my problem with the checkboxes but I need another tip for it

               

              I am creating one text field for each check box, which is hidden. What I need now is to have the text field filled with the email adress corresponding when the check box is ticked, keeping the field hidden.

               

              Once I do this, i'll be able to implement the code up there, taking some text field values to cc the mail aswell.

               

              I don't know if I have been clear enough, but if I have, do you have any idea of the way to do this?

               

              Thank you in advance for your response

              • 4. Re: Conditional submit button w/ checkboxes
                try67 MVP & Adobe Community Professional

                You don't have to do it with another text field. You can use the Export Value of the check-boxes. So you enter the email address as the export value and then you check if the box is checked or not.

                 

                So something like this:

                 

                var cb1 = this.getField("CheckBox1").value;

                if (cb1!="Off") // "Off" is the default value when a box is not ticked

                     cCCAddr += ";" + cb1;

                 

                var cb2 = this.getField("CheckBox2").value;

                if (cb2!="Off")

                     cCCAddr += ";" + cb2;

                 

                etc.

                1 person found this helpful
                • 5. Re: Conditional submit button w/ checkboxes
                  Erwann R Level 1

                  Hey there Gilad, thank you for your help. So I have tried out your code , and tried with 2 check boxes before doing it for all of them.

                  However, I can't get this code to work.

                   

                  I don't know if it may be because by the fact my first checkbox has 2 mails as export value : "address1@fr.transavia.com;address2@fr.transavia.com"

                  my second checkbox has only got 1 adress, let's say "address3@fr.transavia.com"

                   

                  so here's my piece of code. It doesn't say there is any syntax error, however, clicking on it doesn't do anything.

                   

                  -------------

                  var cToAddr="AccueilPN@fr.transavia.com"

                  var cb1=this.getField("Checkbox1").value;

                  if(cb1!="Off")

                  cCCAddr+=";"+cb1;

                   

                   

                  var cb2=this.getField("Checkbox2").value;

                  if(cb2!="Off")

                  cCCAddr+=";"+cb2;

                   

                   

                   

                   

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

                  -----------

                   

                   

                  Any idea of how to get it work?

                   

                  Thank you for your help!

                  • 6. Re: Conditional submit button w/ checkboxes
                    try67 MVP & Adobe Community Professional

                    The code looks fine, but are your checkboxes actually named "Checkbox1" and "Checkbox2"?

                    Are there any error messsages in the JS console when you run the script?

                    • 7. Re: Conditional submit button w/ checkboxes
                      Erwann R Level 1

                      img1.jpgimg2.jpgimg3.jpg

                      I don't get any error message when I validate this javascript code. Here are my boxes names, I have indeed checked out to be sure the names match, and i also attached the export value i've put. I've separated the 2 mailing address by semi colon in the export value.

                       

                      I don't get where I am wrong :/

                      • 8. Re: Conditional submit button w/ checkboxes
                        try67 MVP & Adobe Community Professional

                        Can you share the file? Either upload it to some file-sharing website (dropbox, acrobat.com) and post the link here, or you can send it to me privately at try6767@gmail.com and I'll check it out...

                        • 9. Re: Conditional submit button w/ checkboxes
                          lccdg

                          I'm wondering if this probem was ever solved. I'm having a similar issue, only I want to set the ToAddr field (not CC:), using checkboxes. I've put in the code above, and changed the export field of my checkboxes to the appropriate addresses, and cannot get it to work correctly.

                           

                          I'm also looking to control the subject line based on whichever box is checked. Right now it is hard coded, but I'd like to change that to reflect the checkboxes. In this case, a Master Order vs. a Quote Request.

                           

                          Thanks much!

                           

                          {

                           

                          var cb1 = this.getField("QR").value;

                          if (cb1!="On")

                               cToAddr += ";" + cb1;

                           

                          var cb2 = this.getField("MO").value;

                          if (cb2!="On")

                               cToAddr += ";" + cb2;

                           

                             // Get the client CC email address

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

                           

                             // Set the subject line

                             var cSubLine = "XXX Request: "

                                          + this.getField("JobNum1").value + "-"

                                          + this.getField("JobNum2").value + "-"

                                          + this.getField("JobNum3").value + " Rev "

                                          + this.getField("RevNum").value + " "

                                          + this.getField("CLIENT").value + " "

                                          + this.getField("PROJECTTITLE").value;

                           

                             //  Set the body text for the email message

                             var cBody = "Please see attached Shipping Request.\n" +

                                         "Save the mail attachment for your own records";

                           

                             // Send the entire PDF as a file attachment on an e-mail

                             this.mailDoc({bUI:true, cTo: cToAddr, cCc: cCCAddr,

                                            cSubject: cSubLine, cMsg: cBody});

                          }