learn

Form validation, who is first

category: Ask
Created by: Dr.Ferrous

Form validation, who is first

category: Ask
Created by: Dr.Ferrous
twitter google+ facebook pinned 

For a form validation,should the PHP script go first,then the HTML,or vice versa,or maybe its the same either way?

by Rabson J Phiri

 

Validating the form using Javascript or PHP will give you the same result.

But who should do the task and who is first? here comes the important part,

always use both (Javascript and PHP) to validate your forms.

Use Javascript first, and in case it was hacked using any web tools, you still have PHP validation as a plan b and it can't be hacked.

But why using both languages and not just PHP?

Because you must take care of your site's traffic, sending the form from the browser to the server each time the user clicks on "submit" and doing the validation methods will take too much traffic on your site.

But doing the validation methods using Javascript will cost you nothing except loading the library that will help you to do the validation (such as validate.js), and if you load that library from a CDN, then it will totally cost you nothing.

So, use both languages, Javascript to save your site's bandwidth, and PHP as a plan b if your Javascript is compromised.