Which language is recommended to do form validation? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Which language is recommended to do form validation?

I used php in a form validation but I was told it takes more resources than javascript. and I wanted to know which one is more used on real applications? related https://www.sololearn.com/discuss/1258764/?ref=app

11th May 2018, 11:04 PM
Leoulg
Leoulg - avatar
5 Answers
+ 4
It depends on the validation. You should use JS if you only want to check that all the fields are not empty, validate the content of the fields, make sure that the fields have a correct format, etc. Validations in PHP are done to make sure that something will not cause an error in your database (that is, you should use it to avoid duplicate records, verify that there are no errors in the type of your variables, etc)
12th May 2018, 2:02 AM
Mickel
Mickel - avatar
+ 3
The validations in JS are made interactive (depending on the event where you program them), that means that a validation of a field can be done while the user is still writing or before he sends the information. Validations in PHP are done once the information has been sent to the server. This means that it is executed after the user has interacted with the application.
12th May 2018, 5:46 PM
Mickel
Mickel - avatar
+ 2
Both. Use JS to do front end validation (tell the user what needs/doesn't need to be in the form) and use PHP for back-end validation (to make sure the user isn't trying to hack you)
11th May 2018, 11:58 PM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
0
Ok so how does the javascript and php take turns which is first executed the php or js. or does the js do it on the fly(right there on the inputs or after giving it the wrong input)?
12th May 2018, 4:14 PM
Leoulg
Leoulg - avatar
0
ok great thanks🙏🙏
12th May 2018, 6:39 PM
Leoulg
Leoulg - avatar