Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialskyler katz
11,942 PointsJavascript validation vs. Laravel PHP validation
Is it still important to put the data through the Laravel validator if we are using javascript client side validation? Is it better/faster with Laravel to not use Javascript validation and just use the Laravel validation items?
2 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi Skyler,
I'm not familiar with Laravel PHP validation but in general you would want to use both client and server side validation.
Use client validation to improve the user experience. You can let them know right away that their password isn't strong enough for example instead of making them wait for a round trip to the server.
I think client side validation is mainly there to make things nicer for honest people. It does not prevent dishonest people from doing bad things.
Use server side validation for security. You can't trust what you get from the client side. This is where you can double check that what you're getting is what you were expecting to get.
skyler katz
11,942 PointsMany posts I have read suggest that client-side validation is a better user experience (especially on mobile devices).
Chris Dziewa
17,781 PointsClient-side validation is great for user experience. Though imagine a worst case scenario. What if there was a form for a store that had automated its shipping once a form was correctly submitted. If only client-side validation in the form of JavaScript existed, a malicious user could disable JavaScript and potentially not pay for something they order. Server side languages check information after the browser is finished with it. This is always much better for security and assures that valid and required information has been submitted.
Chris Dziewa
17,781 PointsChris Dziewa
17,781 PointsVery well said Jason!
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsThanks Chris! and thanks for giving an example scenario.