3 Replies Latest reply on Jan 21, 2008 3:31 AM by niki tsanov

    Emial Form Trouble

    E.S.D.
      Hi All!

      I am trying to get my validation scripting for my emial form to work, but with no success. I have 4 input fields - name, email, contact and message. Then I have an dynamic text box which displays the "validations" called info. The scripting on my submit button is as follows:

      on (press, release) {
      //
      if (name == "") {
      nameValid = false;
      }
      if (email == "") {
      emailValid = false;
      }
      if (contact == "") {
      contactValid = false;
      }
      if (email == "" || email.indexOf("@") == -1 || email.indexOf(".") == -1) {
      emailValid = false;
      }
      if (message == "") {
      messageValid = false;
      }
      //
      if (nameValid && emailValid && contactValid && messageValid) {
      loadVariables("contact.php",'GET');
      message="";
      name="";
      email="";
      contact="";
      info="Thank you, I will contact you shortly.";
      } else {
      if (!nameValid) {
      info = "Please enter your Name and Surname";
      } else if (!emailValid) {
      info = "Please enter a valid Email address";
      } else if (!contactValid) {
      info = "Please enter your Contact number";
      } else if (!messageValid) {
      info = "Please enter your message.";
      }
      }
      }

      Any help will be appreciated.

      Kind Regards
      Esmarilda
        • 1. Re: Emial Form Trouble
          niki tsanov Level 1
          So in your if statemant if this name,emial,...and etc is some kind of textfield dynamic or input u must put
          if(name.text == "")
          {
          nameValid=true;
          }
          because when you write if(name=="") the action was check the instance name of name try with trace to see what is result.
          • 2. Re: Emial Form Trouble
            E.S.D. Level 1
            Thanx Niki ...
            I edited the scripting a bit ... But still no luck ... maybe i'm missing something. The code is now as follows:

            on (release) {
            NameValid = true;
            ContactValid = true;
            MessageValid=true;
            //
            Name = name.text;
            Email = email.text;
            Contact = contact.text;
            Message = message.text;
            //
            if (Name == "") {
            NameValid = false;
            }
            if (Email == "") {
            EmailValid = false;
            }
            if (Contact == "") {
            ContactValid = false;
            }
            if (Email == "" || Email.indexOf("@") == -1 || Email.indexOf(".") == -1) {
            EmailValid = false;
            }
            if (Message == "") {
            MessageValid = false;
            }
            //
            if (NameValid && EmailValid && ContactValid && MessageValid) {
            loadVariables("contact.php",'GET');
            message="";
            name="";
            email="";
            contact="";
            info="Thank you, I will contact you shortly.";
            } else {
            if (!NameValid) {
            info = "Please enter your Namee and Surname";
            } else if (!EmailValid) {
            info = "Please enter a valid Email address";
            } else if (!ContactValid) {
            info = "Please enter your Contact number";
            } else if (!MessageValid) {
            info = "Please enter your message.";
            }
            }
            }
            • 3. Re: Emial Form Trouble
              niki tsanov Level 1
              So i think they your script has very unduly lines.Try with this one just change in if statement length of the fields.Also i see you want to send data with GET method this is the right way with .load or with sendAndLoad() :)

              on(press) {
              if (Name.text.length<4) {
              trace("Name length field");
              } else if (Email.text.length<4) {
              trace("Email length faild");
              } else if (Contact.text.length<4) {
              trace("Contact length faild");
              } else if (Email.text.indexOf("@") == -1 || Email.text.indexOf(".") == -1) {
              trace("Incorect email");
              } else {
              var myLoad:LoadVars = new LoadVars();
              myLoad.load("send.php?Name="+Name+"&Email="+Email+"&Contact="+Contact);
              }
              };