Forum Moderators: coopster
I have a question which have bothered me for a while - thats to do the validation when a form is submittted:
How can validation be done in the best way? I have come on the alternatives:
1- making the validation in the php after submitting the form
--> then you handle in the server level, but would the data that the user enters still exist when you redirect to the same page (probably globals is needed then)
--> how would the error messages be handled - would you redirect to a totally new page or the same the user came from?
2 - Using Javascript.
--> This I like because you directly apply messages at the instance data is entered.
--> But this is Client side - so its not a REAL validation.
I like the usability of 2) and the consistency of 1)
But what is the best practices?
Im pretty new in PHP/Javascript and web development and do not want to start in a wron direction....
thanks
Yes, I display any form values that they had filled in prior to submittal and show them again on the display, along with any error message(s). Sometimes I will redirect to a new page, but that depends on the error message...maybe they are trying to access a page that they haven't authenticated themselves to yet, so I'll send them to a login page with a corresponding error message.