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

PHP Laravel 4 Basics Validation & Flash Messages Flash Messages and Errors

Bootstrap form validation

How can I do this in bootstrap found here http://getbootstrap.com/css/#forms-control-validation for error messages?

Colton Fitzgerald
Colton Fitzgerald
15,815 Points

This kind of validation would be done clientside using something like Javascript/jQuery, etc. For example:

    var formInput = getElementById("input1");
    if (formInput.value = ' ') {
        formInput.className = "has-error";
    }

1 Answer

That part of Bootstrap is just a group of CSS styles for indicating the 'validation state' of each form field.

You need to write the logic to determine what is valid/invalid/required, etc. somewhere else, such as in PHP (to display styles initially on page load or after submitting) or as Colton Fitzgerald has mentioned, with any of a number of JavaScript libraries for form validation.

You would then just add or remove the CSS classes from the form elements as appropriate (and as explained in the documentation you linked to).

A search on Github would give you a good place to start looking for something appropriate: https://github.com/search?o=desc&q=form+validation&s=stars&type=Repositories