How to check forms in PHP

Is it better to validate PHP forms with php and then redirect with errors or is it better to use javascript validation and then just allow form submission if javascript is enabled.

+4
source share
5 answers

use javascript to check the format, e.g. email format, password length, etc.

use php to check for db if the same entry exists, e.g. same username

besides hackers, 99% ppl enable javascript, so just throw this problem.

here I recommend the jquery validation plugin for client-side validation.

+1
source

You must check the values ​​on the server side, as the client cannot be trusted.

You can check the values ​​on the client side to provide the best UX for those with JavaScript enabled.

+11
source

I usually do both. If you can check the fields in javascript, this will save them from loading time and save your server from getting into it. You still have to check the server again in case they turned off javascript or intentionally bypassed it.

+4
source

It is better to do both together, because php can process the raw request without using or activating javascript, javascript, can speed up the verification process and process it in an elegant graphical way.

+1
source

Definitely both. Users can disable Javascript or even edit your script check, as it is local (using Firebug or some other such tool). Yes, this means that you are likely to write the same script check in two separate languages ​​at about the same time, but this is an important way to avoid sending incorrect or distorted data.

+1
source

Source: https://habr.com/ru/post/1346749/


All Articles