Which language is better to validate forms ? | Sololearn: Learn to code for FREE!

+6

Which language is better to validate forms ?

Guys, which language do you recommend for validate forms, JavaScript or PHP ? I would like too creat a register sistem, but i need to validate too.

6/25/2019 12:37:41 AM

Matheus Rodrigues

12 Answers

New Answer

+20

I use both as every other web developer. Here are some examples: 1. Username must be at least 3 characters long. Use Javascript. It can handle it and it's the fastest way. 2. Username must be unique. If you store usernames in a database (MYSQL, I Postgresql and similar), the most effective way of validation will be with PHP. 3. Username must contain only Latin letters. Javascript has a solution to this. Basically, if validation requires comparison to database values - use PHP. If it doesn't - use Javascript. P.S. Anyone can take JS code from your website, because it is public. But no one can replace your code with theirs. It requires access to your server.

+5

✅In my opinion it depends, however you can use for client side validation javascript and for server side validation you can use php.

+4

Better is all questionable. For less complex experience, i would say PHP. But if you have some experience on JS, doing it at Node may sound better for you

+4

I think js is better among all because it is better to validate the form on the local browser rather than sending query to the server...and then validating the details..

+3

I think PHP but this is not an expert opinion.

+3

Both. If you just have javascript, it will be possible to manually send a request (tools like postman, or just use a console/write a simple program to send a request) to bypass the validations. If you have just backend validation (php), it will be slower for the end user, but safe from sending requests from other places. By using both, you keep the speed up for normal users with client side validation, while also protecting from people sending requests through other sources with backend validation. As others have mentioned, some validations are only possible to check server side (or at least interaction with the server/ajax), and in that case there is no way around server side validation.

+3

Matheus Rodrigues I didn't read your comment about modifying js before and if it's possible to send invalid data. I answered this in my main answer, but to specifically answer that, yes it is. They can modify and bypass your validations, which is why it is good to have client side validations for speed, and the same (+ more) validations on the server side, in case the client code is modified.

+2

thanks Igor Makarsky you facilitated a lot !

+2

JS Coder i was hopping for this answer haha ! thanks man

+2

No doubt PHP very modernized and sophisticated and widely recommended as per safety measures

+1

Thanks guys, but its true that php is more safe ? someone told me that anyone can change the code of js and put bad information, it is true ?

+1

I would say PHP better