Form validation with javascript or PHP?

Discussion in 'HTML & Website Design' started by NoamBarz, Apr 25, 2007.

  1. #1
    It used to be the case that most form validations were done using javascript. However, it's been a while since I last saw a site using this method. Instead, everyone seems to be using server side validation techniques. Which is better? Client-side javascript, server-side scripting or both?
     
    NoamBarz, Apr 25, 2007 IP
  2. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
    #2
    A combination of both is best.
    a) it prevents the round-trip to the server, because the validation can happen before the form is submitted
    b) if anything gets past the javascript, the PHP can do further validation, and even MX lookups on email addresses
     
    frankcow, Apr 25, 2007 IP
  3. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Thanks. Could you maybe say a little more about "MX lookups". Never heard of those...
     
    NoamBarz, Apr 25, 2007 IP
  4. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
  5. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Thanks! Very useful code.
     
    NoamBarz, Apr 25, 2007 IP
  6. Ronsuave87

    Ronsuave87 Peon

    Messages:
    97
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I use that code myself on the feedback part of my website (see sig)

    I use only PHP because I don't want to bother with JS, lol. :)
     
    Ronsuave87, Apr 25, 2007 IP