15 Replies Latest reply on Sep 17, 2008 2:06 PM by George_Johnson

    Conditional Submit

      I am using a submit command to email an entire PDF document to a department for looking over. I need the subject of the email to change depending on the value of a set of Radio buttons I have place on the form. Does anyone have an idea of how to script this? Thanks!
        • 1. Re: Conditional Submit
          George_Johnson MVP & Adobe Community Professional
          You'll have to use the mailDoc method. How do you currently have it the "submit" action set up? What are the export values of the radio buttons?

          George
          • 2. Re: Conditional Submit
            Level 1
            export values are New, Change, Replace, and Hotcode

            I am using the submitForm command however Acrobat 8 doesn't want to take it of a an IF var statement. I'm new to coding so If that ,makes no sense just tell me and I'll restate in another way.
            • 3. Re: Conditional Submit
              George_Johnson MVP & Adobe Community Professional
              OK. What you can do set up some code to associate the export values of your check boxes with the corresponding email subject line text that you want to use. I'd suggest setting up an object for this, something like:


              // Set up an object to associate a field value
              // with a subject line
              var em_subj = {
                  "New": "This is a sample subject line for this value.",
                  "Change": "This is another subject line.",
                  "Replace": "Yet another subject line.",
                  "Hotcode": "This is the last subject line"
              }

              // Get the value of the radio button field
              var v1 = getField("your_radio").value;

              // E-mail the PDF if the user has made a selection
              if (v1 != "Off") {
                  mailDoc({
                      cTo: "user@example.com; another1@example.com",
                      cSubject: em_subj[v1],
                      cMsg: "E-mail body text goes here. See attached PDF."
                  });
              } else {
                  app.alert("Please select one of the radio buttons.", 3);
              }


              This code is intended to be placed in the Mouse Up event of a button. You'll want to check the Acrobat JavaScript Reference for more information about the doc.mailDoc method. You will have to replace "your_radio" above with the name of your radio button fields, and replace the generic text and e-mail addresses to suit your needs.

              George
              • 4. Re: Conditional Submit
                Level 1
                awesome... I'll test it tomorrow and tell you how I do. Thanks a ton!
                • 5. Re: Conditional Submit
                  Level 1
                  It works great. I tested it already = ). Now to complicate things.
                  I have another set of radio buttons that determines if a Hotcode is from lost or stolen issues. I would like to be able to add LOST or Stolen in the subject line after the hotcode subject if need be depending on what,if any, of those boxes are selected. Preferable by setting another var in the subject line. What you have given me is great but I'm very new to all this so excuse my ignorance on the subject. Thanks for your help!
                  • 6. Re: Conditional Submit
                    George_Johnson MVP & Adobe Community Professional
                    So what are the export values of the other radio buttons, and how exactly would you like "LOST" or "Stolen" to appear in the subject line? What if neither is selected? Perhaps you could show some samples.

                    George
                    • 7. Re: Conditional Submit
                      Level 1
                      basically if it is marked lost or stolen I would like a _LOST or _STOLEN added to the subject line of the email. I think I will need it to test if it is null, Because I only need it to add that if a value is entered.

                      So if my first radio is marked hotcode, I need it to check a second optional radio. If it has a value, I would like it to add to the subject line, if not I would like it to not do anything. I'm not sure If I can put two variables in the subject line or do it another way.

                      The other idea I had was to have the submit check the second radio group and if it has a value to override the first radio group on the subject variable.

                      An example would be. If someone chose the hotcode option and then they selected the second radio stolen option as well, It would read Hotcode_STOLEN in the subject line.

                      Thanks a ton for your help george I really appreciate it.
                      • 8. Re: Conditional Submit
                        George_Johnson MVP & Adobe Community Professional
                        Here's part of the code above modified to do what I think it is you want. I'm assuming the export values of the second radio button group are set appropriately:

                        // Get the value of the radio button field
                        var v1 = getField("your_radio").value;

                        // Get the value of the other radio button field
                        var v2 = getField("your_other_field").value;

                        // Initialize subject line suffix
                        var subj_suffix = "";

                        // Determine subject line suffix
                        // underscore + export value of check box field
                        if (v2 != "Off") {
                            subj_suffix = "_" + v2;
                        }

                        // E-mail the PDF if the user has made a selection
                        if (v1 != "Off") {
                            mailDoc({
                                cTo: "user@example.com; another1@example.com",
                                cSubject: em_subj[v1] + subj_suffix,
                                cMsg: "E-mail body text goes here. See attached PDF."
                            });
                        } else {
                            app.alert("Please select one of the radio buttons.", 3);
                        }

                        If reference to a comment you made above, note that a field value will never be null, which is a special value in JavaScript, so testing against will be misleading. A radio button or check box field value is either the string "Off" (but not "off", false, null, or anything else) or whatever you've set the export value to.

                        George
                        • 9. Re: Conditional Submit
                          Level 1
                          Thanks a ton George. I have no scripting or Adobe experience and I got thrown into the responsibility when the other guy who did it quit. lol. I'm learning though. This really helps me out and I'm sure i can take it from here. You are very appreciated and I am grateful.

                          Thanks

                          David
                          • 10. Re: Conditional Submit
                            Level 1
                            The code you gave me the second time made the submit button stop working, but since you had given me such a clear understanding I ended up tweaking it a bit and making it work. Here is what is ended up being:

                            // Set up an object to associate a field value
                            // with a subject line
                            var em_subj = {
                            "New": "title",
                            "Change": "title",
                            "Replace": "title",
                            "Hotcode": "title"
                            } // Get the value of the radio button field
                            var v1 = getField("Type").value;
                            var em_sub2 = {
                            "LOST": "_Lost",
                            "STOLEN": "_STOLEN"
                            }
                            // E-mail the PDF if the user has made a selection
                            var subj_suffix = " ";
                            var v2 = getField("lost_stolen").value;
                            if (v2 !="Off") {
                            subj_suffix = em_sub2[v2];
                            }
                            if (v1 != "Off") {
                            mailDoc({
                            cTo: "emailjunkie@yaya",
                            cSubject: em_subj[v1] + subj_suffix,
                            cMsg: "Please see attached PDF."
                            });
                            } else {
                            app.alert("Please select one of the radio buttons.", 3);
                            }

                            Thanks for your help... but now I have come across another problem. Since the button is no longer the default adobe submit button, it is no longer checking my other required fields. Am I going to have to assign variables to all my required fields and have them checked? Or is there an easier way to do this?
                            • 11. Re: Conditional Submit
                              George_Johnson MVP & Adobe Community Professional
                              Yes, since you are not submitting, you need to add some code to check each required field individually and only proceed with sending the e-mail if everything checks out. This is far more flexible anyway. Relying on the "required" field property and Acrobat's behavior when a required field is blank is not the best approach.

                              Depending on how thorough you want to be, this can be simple or complicated. For example, if you have a field where a user is required to enter an e-mail address, you can check to see if it's not blank (simple, like Acrobat would do) or passes a strict test for a valid address.

                              I'm hesitant to suggest specific code to do this for a number of reasons, but do post again if you need more guidance.

                              George
                              • 12. Re: Conditional Submit
                                Level 1
                                Well that would be great but these forms are not something I will be using. I basically have to make them stupid proof =(. I had most of it set up As required fields and a lot of it as specific formats. Is there a way to make acrobat think it is submitting or a way to reevaluate the required fields? I have been trying to use the Javascript for Acrobat API as a reference but everything I try doesn't end up working out. Might there be a way to accomplish this by using the submitform()? I'm on a timeline unfortunately so I'm trying to keep this as simple and functional as possible. Thanks a ton!
                                • 13. Re: Conditional Submit
                                  George_Johnson MVP & Adobe Community Professional
                                  How many required fields are there?

                                  George
                                  • 14. Re: Conditional Submit
                                    Level 1
                                    There are 16 of them.
                                    • 15. Re: Conditional Submit
                                      George_Johnson MVP & Adobe Community Professional
                                      OK, Here's a simple routine meant for demonstration purposes. I wouldn't code it this way myself, but I need to keep it simple to demonstrate the idea. Below is a function you can call to do the checking of the required fields. The function returns a value of true if everything is OK, and false otherwise. It should be called before the other code, and the other code can be called if the function returns a value of true. Again, this is simplistic to get the basic idea across.

                                      function checkRequiredFields() {

                                          // Initialize return value;
                                          var bOK = true;

                                          // Check the first text field
                                          if (getField("text1").value === "") {
                                              app.alert("Please fill-in text field text1.");
                                              bOK = false;
                                          }

                                          // Check a radio button field
                                          if (getField("radio1").value === "Off") {
                                              app.alert("Please select an option for the radio1 field.");
                                              bOK = false;
                                          }

                                          // Continue for any other fields

                                          // Return flag indicating success or failure
                                          return bOK;
                                      }

                                      // Check the required fields and send e-mail if everything check out
                                      if (checkRequiredFields()) {
                                          // Place previous code here

                                      } else {

                                          app.alert("Because some required fields were not complete...");
                                      }


                                      George