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 trialKieran Barker
15,028 PointsIs automatic HTML form validation sufficient?
Imagine I had the following HTML. Please pay particular attention to the <required>
attribute on the <input>
element.
<form action="/action_page_post.php" method="post">
<input type="text" name="fname" required>
<input type="submit" value="Submit">
</form>
Would this type of automatic form validation be sufficient on a simple form, or is JavaScript/PHP/some other kind of validation definitely necessary?
1 Answer
Ari Misha
19,323 PointsHiya there! The required attribute only ensures that this field is required and shouldnt be empty. Forms in back-end is like an another different world, where you store the details filled by user in your database , and also sanitize the entries whilst validating 'em as well. And password gets encrypted and added salt in order to store 'em in your database and a session is created if this is a sign up or sign in form. So yeah a lots of stuff happens in back-end when the app processes a form. But HTML only take cares of your front-end or markup on your webpage.
~ Ari
Kieran Barker
15,028 PointsKieran Barker
15,028 PointsThanks for your input, Ari! No pun intended. The thing is, I've noticed that HTML can check if some input fields are formatted correctly. For example, when I use the following HTML code for an email input field:
Then the browser returns the following error message if the entered email address isn't formatted correctly:
What do you think? :-)
Ari Misha
19,323 PointsAri Misha
19,323 PointsKieran Barker of course HTML can, but in real world applications , you'll hardly see this kinda validation. And its just very basic validation but yeah its still validation and its still useful. Plus you already gave it a type to email , so yeah behind the scenes it performs basic validation to check if the entries are correct or not. (: