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

HTML

Kieran Barker
Kieran Barker
15,028 Points

Is 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
Ari Misha
19,323 Points

Hiya 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
Kieran Barker
15,028 Points

Thanks 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:

<form action="newsletter.html" method="post" id="newsletter_form">
  <label for="newsletter">Mailing List</label><br>
  <input type="email" id="newsletter" name="visitor_newsletter" placeholder="Enter your email address..." required><br>
  <button type="submit">Sign Up</button>
</form>

Then the browser returns the following error message if the entered email address isn't formatted correctly:

E-mail input error

What do you think? :-)

Ari Misha
Ari Misha
19,323 Points

Kieran 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. (: