Do you validate your forms with javascript or php?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • varois83

    #1

    Do you validate your forms with javascript or php?

    Hi

    Newbie here. I have been working on creating a guestbook for my site as
    practice and am learning a lot.
    Do you guys validate your forms first on the client with javascript and
    then on the server with PHP or just use one of the two and if yes which
    one?
    I don't want to reinvent the wheel too much.

    Thanks a lot

    Patrick

  • Dani CS

    #2
    Re: Do you validate your forms with javascript or php?

    varois83 wrote:[color=blue]
    > Hi
    >
    > Newbie here. I have been working on creating a guestbook for my site as
    > practice and am learning a lot.
    > Do you guys validate your forms first on the client with javascript and
    > then on the server with PHP or just use one of the two and if yes which
    > one?
    > I don't want to reinvent the wheel too much.[/color]

    Javascript + PHP, or PHP alone. Never Javascript alone.

    With Javascript you avoid involving the server, so it works faster. But
    all the data that gets to the server MUST be validated. All and every
    remote vulnerabilities come from bad validation on the server side.

    If you want to code validation only once, go for PHP.
    [color=blue]
    >
    > Thanks a lot
    >
    > Patrick
    >[/color]

    Comment

    • Michael Fesser

      #3
      Re: Do you validate your forms with javascript or php?

      .oO(varois83)
      [color=blue]
      >Do you guys validate your forms first on the client with javascript and
      >then on the server with PHP or just use one of the two and if yes which
      >one?[/color]

      You can use client-side validation (JS) for convenience, so the user
      gets an immediate feedback if something's wrong, but nevertheless you
      _must_ validate _all_ submitted data on the server. Never trust any
      incoming data.

      You might also want to read this:

      Javascript form validation – doing it right
      Deze pagina bestaat niet of is niet meer beschikbaar. Oude XS4ALL-homepages zijn soms nog terug te vinden via webarchieven.


      Micha

      Comment

      • Manuel Lemos

        #4
        Re: Do you validate your forms with javascript or php?

        Hello,

        on 01/04/2005 10:47 PM varois83 said the following:[color=blue]
        > Newbie here. I have been working on creating a guestbook for my site as
        > practice and am learning a lot.
        > Do you guys validate your forms first on the client with javascript and
        > then on the server with PHP or just use one of the two and if yes which
        > one?
        > I don't want to reinvent the wheel too much.[/color]

        In that case you may want to try this forms generation and validation
        class that can perform several common types of validation on the server
        side and can also generate the necessary Javascript code to perform the
        same types of validation can that be performed on the client site.

        http://www.phpclasses.org/formsgeneration

        --

        Regards,
        Manuel Lemos

        PHP Classes - Free ready to use OOP components written in PHP
        http://www.phpclasses.org/

        PHP Reviews - Reviews of PHP books and other products
        http://www.phpclasses.org/reviews/

        Metastorage - Data object relational mapping layer generator

        Comment

        • Zachary Kessin

          #5
          Re: Do you validate your forms with javascript or php?

          Dani CS <contusiones.me rluza@yahoo.es. quita-la-merluza> writes:
          [color=blue]
          > varois83 wrote:[color=green]
          > > Hi
          > > Newbie here. I have been working on creating a guestbook for my site
          > > as
          > > practice and am learning a lot.
          > > Do you guys validate your forms first on the client with javascript and
          > > then on the server with PHP or just use one of the two and if yes which
          > > one?
          > > I don't want to reinvent the wheel too much.[/color]
          >
          > Javascript + PHP, or PHP alone. Never Javascript alone.
          >
          > With Javascript you avoid involving the server, so it works
          > faster. But all the data that gets to the server MUST be
          > validated. All and every remote vulnerabilities come from bad
          > validation on the server side.
          >
          > If you want to code validation only once, go for PHP.
          >[color=green]
          > > Thanks a lot
          > > Patrick
          > >[/color][/color]

          Do both as much as you can. I use HTML_QuickForm which automates this
          to a great extent. It has most of the basic validation rules you
          could want, and will automaticly run them on both sides for you.

          --Zach

          Comment

          • Chung Leong

            #6
            Re: Do you validate your forms with javascript or php?

            "varois83" <varois83@netze ro.net> wrote in message
            news:1104886029 .589024.196510@ c13g2000cwb.goo glegroups.com.. .[color=blue]
            > Hi
            >
            > Newbie here. I have been working on creating a guestbook for my site as
            > practice and am learning a lot.
            > Do you guys validate your forms first on the client with javascript and
            > then on the server with PHP or just use one of the two and if yes which
            > one?
            > I don't want to reinvent the wheel too much.
            >
            > Thanks a lot
            >
            > Patrick
            >[/color]

            Personally, I dislike how client-side validation is usually implemented.
            That is, using alert boxes.

            *** dong! ***

            A good approach I think is to use Javascript to check for missing fields and
            use PHP to validate what's actually entered. It's more consistent, since
            there could be fields that can only be validated on the server-side (e.g.
            duplicated user name). The server can also consolidate and format the error
            messages better.


            Comment

            • Tony Marston

              #7
              Re: Do you validate your forms with javascript or php?


              "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message
              news:VLydnXNMge HOeEDcRVn-jQ@comcast.com. ..[color=blue]
              > "varois83" <varois83@netze ro.net> wrote in message
              > news:1104886029 .589024.196510@ c13g2000cwb.goo glegroups.com.. .[color=green]
              >> Hi
              >>
              >> Newbie here. I have been working on creating a guestbook for my site as
              >> practice and am learning a lot.
              >> Do you guys validate your forms first on the client with javascript and
              >> then on the server with PHP or just use one of the two and if yes which
              >> one?
              >> I don't want to reinvent the wheel too much.
              >>
              >> Thanks a lot
              >>
              >> Patrick
              >>[/color]
              >
              > Personally, I dislike how client-side validation is usually implemented.
              > That is, using alert boxes.
              >
              > *** dong! ***
              >
              > A good approach I think is to use Javascript to check for missing fields
              > and
              > use PHP to validate what's actually entered. It's more consistent, since
              > there could be fields that can only be validated on the server-side (e.g.
              > duplicated user name). The server can also consolidate and format the
              > error
              > messages better.[/color]

              I disagree completely. All data MUST be validated on the server (including
              missing fields) regardless of any EXTRA validation performed on the client
              using javascript. This prevents any checks from not being performed simply
              because the client has disabled javascript.

              Your remark about error messages is also rubbish as ANY message you can
              create using javascript you can also create on the server. You do NOT need
              javascript to create sexy error messages.

              --
              Tony Marston

              This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL




              Comment

              • Chung Leong

                #8
                Re: Do you validate your forms with javascript or php?

                "Tony Marston" <tony@NOSPAM.de mon.co.uk> wrote in message
                news:crl96r$ivg $1$8300dec7@new s.demon.co.uk.. .[color=blue]
                >
                > "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message
                > news:VLydnXNMge HOeEDcRVn-jQ@comcast.com. ..[color=green]
                > > Personally, I dislike how client-side validation is usually implemented.
                > > That is, using alert boxes.
                > >
                > > *** dong! ***
                > >
                > > A good approach I think is to use Javascript to check for missing fields
                > > and
                > > use PHP to validate what's actually entered. It's more consistent, since
                > > there could be fields that can only be validated on the server-side[/color][/color]
                (e.g.[color=blue][color=green]
                > > duplicated user name). The server can also consolidate and format the
                > > error
                > > messages better.[/color]
                >
                > I disagree completely. All data MUST be validated on the server (including
                > missing fields) regardless of any EXTRA validation performed on the client
                > using javascript. This prevents any checks from not being performed simply
                > because the client has disabled javascript.
                >
                > Your remark about error messages is also rubbish as ANY message you can
                > create using javascript you can also create on the server. You do NOT need
                > javascript to create sexy error messages.
                >[/color]

                Next time when you disagree with me completely, can you at least read my
                post first?


                Comment

                • Tony Marston

                  #9
                  Re: Do you validate your forms with javascript or php?


                  "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message
                  news:09adnfesd9 w2qkPcRVn-1w@comcast.com. ..[color=blue]
                  > "Tony Marston" <tony@NOSPAM.de mon.co.uk> wrote in message
                  > news:crl96r$ivg $1$8300dec7@new s.demon.co.uk.. .[color=green]
                  >>
                  >> "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message
                  >> news:VLydnXNMge HOeEDcRVn-jQ@comcast.com. ..[color=darkred]
                  >> > Personally, I dislike how client-side validation is usually
                  >> > implemented.
                  >> > That is, using alert boxes.
                  >> >
                  >> > *** dong! ***
                  >> >
                  >> > A good approach I think is to use Javascript to check for missing
                  >> > fields
                  >> > and
                  >> > use PHP to validate what's actually entered. It's more consistent,
                  >> > since
                  >> > there could be fields that can only be validated on the server-side[/color][/color]
                  > (e.g.[color=green][color=darkred]
                  >> > duplicated user name). The server can also consolidate and format the
                  >> > error
                  >> > messages better.[/color]
                  >>
                  >> I disagree completely. All data MUST be validated on the server
                  >> (including
                  >> missing fields) regardless of any EXTRA validation performed on the
                  >> client
                  >> using javascript. This prevents any checks from not being performed
                  >> simply
                  >> because the client has disabled javascript.
                  >>
                  >> Your remark about error messages is also rubbish as ANY message you can
                  >> create using javascript you can also create on the server. You do NOT
                  >> need
                  >> javascript to create sexy error messages.
                  >>[/color]
                  >
                  > Next time when you disagree with me completely, can you at least read my
                  > post first?[/color]

                  Your remark "A good approach I think is to use Javascript to check for
                  missing fields and use PHP to validate what's actually entered" implies that
                  you use PHP to validate what is entered and javascript to validate what is
                  *not* entered. My second remark was wrong as I misread what you had written
                  (I mentally substituted 'client' for 'server').

                  Tony Marston


                  Comment

                  • Roy W. Andersen

                    #10
                    Re: Do you validate your forms with javascript or php?

                    varois83 wrote:[color=blue]
                    > Do you guys validate your forms first on the client with javascript and
                    > then on the server with PHP or just use one of the two and if yes which
                    > one?[/color]

                    I do both. I did only serverside when I started out (mostly because my
                    knowledge of JavaScript was limited, at best), but soon moved to doing
                    both consistently. I always keep the thought "never trust the user" in
                    the back of my head when I develop, so in my humble opinion, validating
                    with JavaScript is only for convenience in that it saves time (for the
                    user) and bandwidth (for the site), while validating with PHP is
                    required to make sure the data received is indeed valid. Allowing people
                    to have invalid data stored just by disabling JavaScript on their client
                    is too much of a risk.


                    Roy W. Andersen
                    --
                    ra at broadpark dot no / http://roy.netgoth.org/

                    "Hey! What kind of party is this? There's no booze
                    and only one hooker!" - Bender, Futurama

                    Comment

                    Working...