form validation using PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DDragon
    New Member
    • Aug 2007
    • 15

    form validation using PHP

    I have a couple of forms, at the moment im using JS to validate them, but i would prefer to use PhP but im not quite sure about how to set up validation with it. If anyone can point me in the right direction that would be great.

    DD
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    It's better to use a combination of both PHP and JS to validate your form. PHP would use up bandwidth, while JS doesn't. However, there's no garuntee JS is enabled in the browser!

    Read php form validation.

    Comment

    • ak1dnar
      Recognized Expert Top Contributor
      • Jan 2007
      • 1584

      #3
      Originally posted by markusn00b
      It's better to use a combination of both PHP and JS to validate your form. PHP would use up bandwidth, while JS doesn't. However, there's no garuntee JS is enabled in the browser!

      Read php form validation.
      Server side validation is better when developing high-secure applications. The problem with javascript is, a malicious user has the access to the client side script and easily then can bypass the validation process by removing the scripts. So I'll recommend js when developing simple applications only.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by ak1dnar
        Server side validation is better when developing high-secure applications. The problem with javascript is, a malicious user has the access to the client side script and easily then can bypass the validation process by removing the scripts. So I'll recommend js when developing simple applications only.
        As I said: a combination of both is pretty much *always* required.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          I wouldn't really call JavaScript validation... validation.
          It doesn't really validate anything, as you have both pointed out, a malicious user can, and most likely will, bypass any JavaScript *security* measures.

          It can, however, make sure that a normal user doesn't do stuff like forget to fill out required fields, or that the data he is entering is in fact the data you need.
          Whether that qualifies as validation... I wouldn't call it that, but whatever.

          In any case, you must always validate you data server-side, no matter what you may or may not be doing client-side.
          Like always; relying on client-side code to provide any key functionality is a horrible idea.

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            My argument for JS validation (i will use that term losely now, Atli) is that it would save the user submitting wrong information, waiting for the php script to run, then being redirected back to the form page, all of which might be time consuming.

            Comment

            • 00johnson
              New Member
              • Jul 2008
              • 1

              #7
              I'm doing the same thing at the moment. Try

              it helped me validate text fields along with where to place the code. Also
              PHP form validation tutorial walks you how to validate forms and their inputs with PHP programming language on the server side

              uses the preg_match() function, I have used this for validating numerical fields. They should get you started.
              Look at

              to understand what you are doing, the language reference section has particularly helped me.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Originally posted by Atli
                In any case, you must always validate you data server-side, no matter what you may or may not be doing client-side.
                Like always; relying on client-side code to provide any key functionality is a horrible idea.
                Very true. See Form Validation - doing it right for a nice explanation.

                Comment

                Working...