Best way to validate forms?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jakez
    Confirmed User
    • Jan 2004
    • 5656

    #1

    Best way to validate forms?

    Does anyone have any tricks/tips on validating forms (no plugins)?

    There doesn't really seem to be any universal way to make a javascript function that will suit everything, you almost have to hard code form/input names into the function, which is nasty if you're going to be working with a lot of forms in a project.

    I mean I could make something that checks for empty fields or validates an email address but what if I need to see if a <select> listbox value=="this" and if it does then make sure this <input> field=="this".. things would get really messy..
    [email protected] - jakezdumb - 573689400

    Killuminati
  • Jakez
    Confirmed User
    • Jan 2004
    • 5656

    #2
    Plus you have to worry about people doing malicious things and getting past your javascript validation so you have to also pass everything through PHP or something.
    [email protected] - jakezdumb - 573689400

    Killuminati

    Comment

    • candyflip
      Carpe Visio
      • Jul 2002
      • 43070

      #3
      Tried jquery?

      http://www.webreference.com/programm...rm_validation/

      Spend you some brain.
      Email Me

      Comment

      • fris
        I have to go potty
        • Aug 2002
        • 55758

        #4
        jquery has some nice ones
        Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


        Totally Free Templates

        Comment

        • fatfoo
          ICQ:649699063
          • Mar 2003
          • 27763

          #5
          jquery - I guess that's it.
          Send me an email: [email protected]

          Comment

          • Jakez
            Confirmed User
            • Jan 2004
            • 5656

            #6
            Of course... I'm becoming very familiar with jquery now lol. Still kind of have the same problem though, I guess there will just have to be another function for every form? Gross..
            Last edited by Jakez; 03-07-2010, 07:25 PM.
            [email protected] - jakezdumb - 573689400

            Killuminati

            Comment

            • fris
              I have to go potty
              • Aug 2002
              • 55758

              #7
              Originally posted by Jakez
              Of course... I'm becoming very familiar with jquery now lol. Still kind of have the same problem though, I guess there will just have to be another function for every form? Gross..
              not at all
              Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


              Totally Free Templates

              Comment

              • Jakez
                Confirmed User
                • Jan 2004
                • 5656

                #8
                Ok I have like 20 jquery.com pages open trying to figure out how to do this but none of them work, lets say I have a few of these:
                <select id=stuff[0] name=stuff[0]>
                <option value="thing">Thing</option>
                <option value="other_thing">Other Thing</option>
                </select>

                <select id=stuff[1] name=stuff[1]>
                <option value="thing">Thing</option>
                <option value="other_thing">Other Thing</option>
                </select>
                Ok, I need to go through the stuff[] array and find out if ANY of them have "thing" selected. Major confusion.

                I think the closest I've came is:
                var wtf=$('#stuff[0]').val();
                No luck. Tried the inArray()'s and indexOf()'s and they don't seem to return anything either.
                Last edited by Jakez; 03-08-2010, 04:24 PM.
                [email protected] - jakezdumb - 573689400

                Killuminati

                Comment

                • Jakez
                  Confirmed User
                  • Jan 2004
                  • 5656

                  #9
                  I can get the value of a <select> just fine, but since I have many of them stored into an array it's made this a lot more difficult.
                  [email protected] - jakezdumb - 573689400

                  Killuminati

                  Comment

                  • Jakez
                    Confirmed User
                    • Jan 2004
                    • 5656

                    #10
                    LOL I think I finally stumped everyone. I did find a solution though:

                    var selects = $("select[name^=stuff]");
                    var wtf = $.inArray("thing",selects.map(function() { return $(this).val(); }).get()) > -1;
                    Returns true or false.
                    [email protected] - jakezdumb - 573689400

                    Killuminati

                    Comment

                    Working...