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 trial
Joe Morello
1,734 PointsValidate contact form
I have the web site of my client, I need to validate the contact form to send the message to mail it.
4 Answers
Kevin Korte
28,149 PointsYou always need to validate server side. Always always always. Validating client side with javascript is just to ease frustrations from user trying to fill out your form who may have made an error. This way they do not need to wait for a form submit and a page refresh to find out they had an error. You can provide that feedback instantly with Javascript.
However, anybody looking to do anything malicious can easily get around client side validation like javascript. Don't forget that JS gets executed in the browser. Which means it can be disabled, or your JS validation code can be changed with browser dev tools just like the html and css of any site can be changed by the user for their computer.
So, I could change your JS validation to accept my malicious code, and if you didn't have server side validation, than there is nothing left to stop me.
If you have to pick one, always pick server side validation, or at least work on that one first.
Cassio Victor Cadore
6,579 PointsJosé, what kind of validation do you want? Just check if the fields are filled? Or checking if it is a valid email? There are many ways of validating forms, but none of them are done using HTML. You should look on the internet of ways of doing it on the client-side with Javascript, or in the server-side with PHP/ASP/RAILS.
Joe Morello
1,734 PointsWell, if I had to do it for PHP or JAVASCRIPT what is the method or syntax?
Cassio Victor Cadore
6,579 PointsI believe that discussing how to make things that are not taught by Treehouse is out of the scope of this Forum, so here are two examples you can follow:
Joe Morello
1,734 PointsOk, thank you.
Joe Morello
1,734 PointsJoe Morello
1,734 PointsSure! I will do this so that all site is good. thank you very much.