Do you validate your forms with javascript or php?

This is a discussion on Do you validate your forms with javascript or php? within the PHP Language forums, part of the PHP Programming Forums category; Hi Newbie here. I have been working on creating a guestbook for my site as practice and am learning a ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-05-2005
varois83
 
Posts: n/a
Default 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

Reply With Quote
  #2 (permalink)  
Old 01-05-2005
Dani CS
 
Posts: n/a
Default Re: Do you validate your forms with javascript or php?

varois83 wrote:
> 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.


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.

>
> Thanks a lot
>
> Patrick
>

Reply With Quote
  #3 (permalink)  
Old 01-05-2005
Michael Fesser
 
Posts: n/a
Default Re: Do you validate your forms with javascript or php?

.oO(varois83)

>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?


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
http://www.xs4all.nl/~sbpoley/webmatters/formval.html

Micha
Reply With Quote
  #4 (permalink)  
Old 01-05-2005
Manuel Lemos
 
Posts: n/a
Default Re: Do you validate your forms with javascript or php?

Hello,

on 01/04/2005 10:47 PM varois83 said the following:
> 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.


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
http://www.meta-language.net/metastorage.html
Reply With Quote
  #5 (permalink)  
Old 01-05-2005
Zachary Kessin
 
Posts: n/a
Default Re: Do you validate your forms with javascript or php?

Dani CS <contusiones.merluza@yahoo.es.quita-la-merluza> writes:

> varois83 wrote:
> > 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.

>
> 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.
>
> > Thanks a lot
> > Patrick
> >


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
Reply With Quote
  #6 (permalink)  
Old 01-07-2005
Chung Leong
 
Posts: n/a
Default Re: Do you validate your forms with javascript or php?

"varois83" <varois83@netzero.net> wrote in message
news:1104886029.589024.196510@c13g2000cwb.googlegr oups.com...
> 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
>


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.


Reply With Quote
  #7 (permalink)  
Old 01-07-2005
Tony Marston
 
Posts: n/a
Default Re: Do you validate your forms with javascript or php?


"Chung Leong" <chernyshevsky@hotmail.com> wrote in message
news:VLydnXNMgeHOeEDcRVn-jQ@comcast.com...
> "varois83" <varois83@netzero.net> wrote in message
> news:1104886029.589024.196510@c13g2000cwb.googlegr oups.com...
>> 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
>>

>
> 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.


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

http://www.tonymarston.net



Reply With Quote
  #8 (permalink)  
Old 01-07-2005
Chung Leong
 
Posts: n/a
Default Re: Do you validate your forms with javascript or php?

"Tony Marston" <tony@NOSPAM.demon.co.uk> wrote in message
news:crl96r$ivg$1$8300dec7@news.demon.co.uk...
>
> "Chung Leong" <chernyshevsky@hotmail.com> wrote in message
> news:VLydnXNMgeHOeEDcRVn-jQ@comcast.com...
> > 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.

>
> 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.
>


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


Reply With Quote
  #9 (permalink)  
Old 01-07-2005
Tony Marston
 
Posts: n/a
Default Re: Do you validate your forms with javascript or php?


"Chung Leong" <chernyshevsky@hotmail.com> wrote in message
news:09adnfesd9w2qkPcRVn-1w@comcast.com...
> "Tony Marston" <tony@NOSPAM.demon.co.uk> wrote in message
> news:crl96r$ivg$1$8300dec7@news.demon.co.uk...
>>
>> "Chung Leong" <chernyshevsky@hotmail.com> wrote in message
>> news:VLydnXNMgeHOeEDcRVn-jQ@comcast.com...
>> > 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.

>>
>> 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.
>>

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


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


Reply With Quote
  #10 (permalink)  
Old 01-09-2005
Roy W. Andersen
 
Posts: n/a
Default Re: Do you validate your forms with javascript or php?

varois83 wrote:
> 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 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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:50 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0