5 Replies Latest reply on May 18, 2007 1:04 PM by kglad

    form input validation

    jbradar Level 1
      I made a contact form in Flash 8 Pro and I'm trying to validate the input before sending. All i want to do is verify that the user has entered something in each field. I'm using an if/else, but I can't get it to work properly. It seems that no matter what condition i use, it always returns the same value whether the fields are completed or not.

      I made three fields called inputName, inputEmail, and inputComments. Here is the AS:

      submitBtn.onRelease = function() {
      if (inputName.length && inputEmail.length && inputComments.length) {
      feedbackText.text = "Sending";
      _parent.gotoAndStop(2);
      } else {
      feedbackText.text = "Please fill out all fields.";
      }
      }

      I also tried this for the condition:
      if (inputName.length > 0 && inputEmail.length > 0 && inputComments.length > 0)

      I've also tried to reverse it so it will check it the fields are NOT filled in, like this:
      if (inputName.text = "" || inputEmail.text = "" || inputComments.text = "")

      and like this:
      if (!inputName.length || !inputEmail.length || !inputComments.length)

      Nothing is working. Can anybody tell me the correct way to validate text input?
        • 1. Re: form input validation
          ChrisFlynn Level 1
          You don't seem to be checking for boolean values in your if statement.

          Try this:

          if ((inputName.length>0) && (inputEmail.length>0) && (inputComments.length>0)) {

          Chris
          • 2. Re: form input validation
            jbradar Level 1
            I tried that and it didn't work, but i think it was because of some other code that i removed. I got it to work somewhat, but now I have another problem. Here is the AS now:

            submitBtn.onRelease = function() {
            if ((inputName.text.length == 0) || (inputEmail.text.length == 0) || (inputComments.text.length == 0)) {
            feedbackText.text = "Please fill out all fields.";
            } else {
            feedbackText.text = "Sending";
            }
            }


            Now it will not validate the inputComments text field. If I leave the form blank or fill in only name or e-mail, it will correctly tell the user to fill in all fields. But, if I fill in the name and email fields but leave comments blank, it still reacts as if all fields were filled in. The only difference is that the name and email fields are single line text input fields and the comments field is a multiline text input field. So, I turned the comments field in to a single line field and now it works!!! So, I guess my problem is, how can i validate a multiline text field?
            • 3. Re: form input validation
              kglad Adobe Community Professional & MVP
              disable the html property and kerning of your textfield, if they are not needed. if they are needed you can still work out a solution, just let us know which properties are needed.
              • 4. Re: form input validation
                jbradar Level 1
                I disabled the kerning and that did the trick. Thanks a ton, I was about to start pulling out hair!
                • 5. Re: form input validation
                  kglad Adobe Community Professional & MVP
                  you're welcome.