5 Replies Latest reply on Feb 9, 2011 6:40 AM by kglad

    AS2 Form Validation

    BlackOpsRanger

      I posted here last week and got some good info grom Ned and Kglad. I tried various ways to incorporate the information they provided but I can't seem to fit it all together. I have a form with some basic validation that works pretty well, except when a users presses the spacebar. In other words, my current validation requires that users input "something" into each required field. Unfortunately, this "something" can easily be one press of the spacebar. Apparently the spacebar contains a value of some sort, which I cannot figure out. Here is my current validation code. Any assistance offered is greatly appreciated. Thanks.

       

      //create the LoadVars objects which will be used later
      //one to send data...
      dataSender = new LoadVars();
      //and one to catch what comes back
      dataReceiver = new LoadVars();

       

      /*DEFINE SUBMIT BUTTON BEHAVIOR*/

       

       

       


      submit_mc.onRelease = function() {
          //final check to make sure fields are completed
      if (
      fname_txt.text != '' &&
      email_txt.text != '' &&
      phone_txt.text != '' &&
      cname_txt.text != '' &&
      cnumber_txt.text != '' &&
      webaddress_txt.text != '' &&
      description_txt.text != '') {
      alert_txt.text='';//clear any previous error messages or warnings
         //advance playhead to frame 2 - the "processing" message
         office-form_mc.play();
         //assign properties to LoadVars object created previously
         dataSender.fname = fname_txt.text;
         dataSender.email = email_txt.text;
         dataSender.phone = phone_txt.text;
         dataSender.city = city_txt.text;
         dataSender.drop = drop_bx.text;
         dataSender.area = area_txt.text;
         dataSender.sales = radioGroup.selection.data;
        
         dataSender.low = low_txt.text;
         dataSender.high = high_txt.text;
         dataSender.footage = footage_txt.text;
         //callback function - how to handle what comes back
      dataReceiver.onLoad = function() {
         gotoAndPlay(2);
      }
      //now send data to script
         dataSender.sendAndLoad("processEmail.php", dataReceiver, "POST");
          } else {
         //warning if user tries to submit before completing form
         alert_txt.text = "Please complete all required fields before submitting form.";
         }
      }

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

          where's the function i suggested you use?


          • 2. Re: AS2 Form Validation
            BlackOpsRanger Level 1

            I really couldn't figure out how to make it work. I still have it, just not sure where to put it. It seems I need more instruction than I originally thought. Your code seemed fairly simple enough to use, but when I started putting it in I got too confused and couldnt get it to work. Sorry, but I guess I'm much more of a novice than I had hoped. I will certainly listen if you care to straighten me out on this. Thanks

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

               

              //create the LoadVars objects which will be used later
              //one to send data...
              dataSender = new LoadVars();
              //and one to catch what comes back
              dataReceiver = new LoadVars();

               

              /*DEFINE SUBMIT BUTTON BEHAVIOR*/

               

               

               


              submit_mc.onRelease = function() {
                  //final check to make sure fields are completed
              if (tfCheck(fname_txt)&&tfCheck(email_txt)&&tfCheck(phone_txt)&&tfCheck(cname_txt)&&tfCheck( cnumber_txt)&&tfCheck(webaddress_txt)&&tfCheck(description_txt)){

              alert_txt.text='';//clear any previous error messages or warnings
                 //advance playhead to frame 2 - the "processing" message
                 office-form_mc.play();
                 //assign properties to LoadVars object created previously
                 dataSender.fname = fname_txt.text;
                 dataSender.email = email_txt.text;
                 dataSender.phone = phone_txt.text;
                 dataSender.city = city_txt.text;
                 dataSender.drop = drop_bx.text;
                 dataSender.area = area_txt.text;
                 dataSender.sales = radioGroup.selection.data;
                
                 dataSender.low = low_txt.text;
                 dataSender.high = high_txt.text;
                 dataSender.footage = footage_txt.text;
                 //callback function - how to handle what comes back
              dataReceiver.onLoad = function() {
                 gotoAndPlay(2);
              }
              //now send data to script
                 dataSender.sendAndLoad("processEmail.php", dataReceiver, "POST");
                  } else {
                 //warning if user tries to submit before completing form
                 alert_txt.text = "Please complete all required fields before submitting form.";
                 }
              }

               

              function tfCheck(tf:TextField):Boolean{

              var s:String=tf.text.split(" ").join("");

              if(s.length==0){

              return false;

              } else {

              return true;

              }

              }

              • 4. Re: AS2 Form Validation
                BlackOpsRanger Level 1

                That worked perfectly. I don't know how to thank you enough. I wasn't sure I'd ever get this one figured out. Thank you very much.

                Sent from my Verizon Wireless BlackBerry

                • 5. Re: AS2 Form Validation
                  kglad Adobe Community Professional & MVP

                  you're welcome.

                   

                  p.s.  please mark correct/helpful answers.