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

25th Jun 2019, 12:37 AM
Matheus Rodrigues
Matheus Rodrigues - avatar
12 Respuestas
+ 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.
25th Jun 2019, 10:04 PM
Igor Makarsky
Igor Makarsky - avatar
+ 5
✅In my opinion it depends, however you can use for client side validation javascript and for server side validation you can use php.
25th Jun 2019, 3:45 PM
Nithya Yamasinghe
Nithya Yamasinghe - avatar
+ 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
25th Jun 2019, 3:44 AM
Alexander Santos
Alexander Santos - avatar
+ 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..
25th Jun 2019, 4:03 AM
Vishal Sharma
Vishal Sharma - avatar
+ 3
I think PHP but this is not an expert opinion.
25th Jun 2019, 12:48 AM
Sonic
Sonic - avatar
+ 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.
26th Jun 2019, 1:59 AM
JS Coder
+ 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.
26th Jun 2019, 2:18 AM
JS Coder
+ 2
thanks Igor Makarsky you facilitated a lot !
26th Jun 2019, 1:42 AM
Matheus Rodrigues
Matheus Rodrigues - avatar
+ 2
JS Coder i was hopping for this answer haha ! thanks man
26th Jun 2019, 2:39 AM
Matheus Rodrigues
Matheus Rodrigues - avatar
+ 2
No doubt PHP very modernized and sophisticated and widely recommended as per safety measures
26th Jun 2019, 3:51 PM
Aditya
Aditya - avatar
+ 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 ?
25th Jun 2019, 1:09 PM
Matheus Rodrigues
Matheus Rodrigues - avatar
+ 1
I would say PHP better
6th Jul 2019, 11:19 PM
Emad Amir
Emad Amir - avatar