3 Replies Latest reply on Sep 17, 2009 9:06 AM by kglad

    Multiple Form Field Validation

    grover970

      I run throught these series of checks before submitting the variables to the .jsp script. Problem is that it will ignore the sender name and receipient name as long as there are two email addresses. Why is that?

       

      if (sendername eq "") {
              nameerrorTXT.text = "PLEASE ENTER YOUR NAME";
          }
          if (emailfrom.indexOf("@")<0 or emailfrom.indexOf(".")<0) {
              emailfromerror.text= "PLEASE USE A VALID EMAIL ADDRESS";
              emailfromTXT.text = "";
          }
          if (recipientname eq "") {
              recipientnameerrorTXT.text= "PLEASE ENTER YOUR FRIEND'S NAME";
              recipientnameTXT.text = "";
          }
          if (emailto.indexOf("@")<0 or emailto.indexOf(".")<0) {
                  emailtoerror.text= "PLEASE USE A VALID EMAIL ADDRESS";
                  emailtoTXT.text = "";
          } else {
              _root.sendername = sendername;
              _root.recipientname = recipientname;
              _root.emailfrom = emailfrom;
              _root.emailto = emailto;
              _root.emailsubject = sendername + " " + emailsubject;
              _root.emailbody = emailbody;
              _root.loadVariables("/jsp/sendMail.jsp", "POST");
              sendernameTXT.text = "";
              recipientnameTXT.text = "";
              emailfromTXT.text = "";
              emailtoTXT.text = "";
              nextFrame();
          }

        • 1. Re: Multiple Form Field Validation
          kglad Adobe Community Professional & MVP

          because that's the only if-else statement.  try:

           


           

          if (sendername eq "") {
                  nameerrorTXT.text = "PLEASE ENTER YOUR NAME";
              } else if (emailfrom.indexOf("@")<0 or emailfrom.indexOf(".")<0) {
                  emailfromerror.text= "PLEASE USE A VALID EMAIL ADDRESS";
                  emailfromTXT.text = "";
              } else if (recipientname eq "") {
                  recipientnameerrorTXT.text= "PLEASE ENTER YOUR FRIEND'S NAME";
                  recipientnameTXT.text = "";
              } else if (emailto.indexOf("@")<0 or emailto.indexOf(".")<0) {
                      emailtoerror.text= "PLEASE USE A VALID EMAIL ADDRESS";
                      emailtoTXT.text = "";
              } else {
                  _root.sendername = sendername;
                  _root.recipientname = recipientname;
                  _root.emailfrom = emailfrom;
                  _root.emailto = emailto;
                  _root.emailsubject = sendername + " " + emailsubject;
                  _root.emailbody = emailbody;
                  _root.loadVariables("/jsp/sendMail.jsp", "POST");
                  sendernameTXT.text = "";
                  recipientnameTXT.text = "";
                  emailfromTXT.text = "";
                  emailtoTXT.text = "";
                  nextFrame();
              }

          1 person found this helpful
          • 2. Re: Multiple Form Field Validation
            grover970 Level 1

            Thanks Klad,

             

            I actually tried that route. The problem was that if any one of those 'if' statements were true the the function would stop and I needed the function to check AND respond to each field if needed. I found that the 'else' statement would fire regardless to all the 'if' statements except for the one just before it.

             

            I'm sure there is a better way to do and I'd like to know how but I solved the issue by creating a last 'if' statement that lumped all the if statements together. This way I would achieve the error feedback needed AND keep the 'ELSE' statement from firing. See below

             

            submitBNT.onPress = function(){

             

                if (sendername eq undefined | sendername eq "") {
                    nameerrorTXT.text = "PLEASE ENTER YOUR NAME";
                    sendernameTXT.text = "";
                }


                if (emailfrom.indexOf("@")<0 | emailfrom.indexOf(".")<0) {
                    emailfromerror.text= "PLEASE USE A VALID EMAIL ADDRESS";
                    emailfromTXT.text = "";
                }


                if (recipientname eq undefined | recipientname eq "") {
                    recipientnameerrorTXT.text= "PLEASE ENTER YOUR FRIEND'S NAME";
                    recipientnameTXT.text = "";
                }
                if (emailto.indexOf("@")<0 | emailto.indexOf(".")<0) {
                        emailtoerror.text= "PLEASE USE A VALID EMAIL ADDRESS";
                        emailtoTXT.text = "";
                }
                if (sendername eq undefined | sendername eq "" | emailfrom.indexOf("@")<0 or emailfrom.indexOf(".")<0 | recipientname eq undefined | recipientname eq "" | emailto.indexOf("@")<0 or emailto.indexOf(".")<0) {
                    /// DO NOTHING
                } else {
                    processMailForm();
                }
            }

            • 3. Re: Multiple Form Field Validation
              kglad Adobe Community Professional & MVP

              you're welcome.

               

              the way is usually do this is to assign a variable a boolean to determine if all the fields are ok.  something like:

               

              var emailOK:Boolean=true

               

              if(one thing's wrong){

              emailOK=false;

              display whatever

              }

              if(anothere thing's wrong){

              emailOK=false;

              display something

              }

              .

              .

              .

              if(emailOK){

              call php script.  nothing wrong was found

              }

              1 person found this helpful