Powerful jQuery Bootstrap Form Validation with Example
Here is another example to validate your bootstrap form using jquery. This is very simple and user friendly plugins to validate your bootstrap form with additional features.
Using this plugin you can validate form easily.
This will shows you error icon and success icon too.
Here is a sample form to validate via jquery bootstrap validator.
- {!! Form::open(array('route' => 'your route','method'=>'POST','files'=>true,'id'=>'myform')) !!}
- <div class="col-xs-12 col-sm-12 col-md-12">
- <div class="form-group">
- <strong>Name:</strong>
- {!! Form::text('name', null, array('placeholder' => 'Name','class' => 'form-control')) !!}
- {!! $errors->first('name', '<p class="alert alert-danger">:message</p>') !!}
- </div>
- </div>
- <div class="col-xs-12 col-sm-12 col-md-12">
- <div class="form-group">
- <strong>Email:</strong>
- {!! Form::text('email', null, array('placeholder' => 'Email','class' => 'form-control')) !!}
- {!! $errors->first('email', '<p class="alert alert-danger">:message</p>') !!}
- </div>
- </div>
- <div class="col-xs-12 col-sm-12 col-md-12">
- <div class="form-group">
- <strong>Phone:</strong>
- {!! Form::text('phone', null, array('placeholder' => 'Mobile No','class' => 'form-control')) !!}
- {!! $errors->first('phone', '<p class="alert alert-danger">:message</p>') !!}
- </div>
- </div>
- <div class="col-xs-12 col-sm-12 col-md-12">
- <div class="form-group">
- <strong>Details:</strong>
- {!! Form::textarea('details', null, array('placeholder' => 'Details','class' => 'form-control','style'=>'height:100px')) !!}
- {!! $errors->first('details', '<p class="alert alert-danger">:message</p>') !!}
- </div>
- </div>
- <div class="col-xs-12 col-sm-12 col-md-12 text-center">
- <button type="submit" class="btn btn-primary">Submit</button>
- </div>
- {!! Form::close() !!}
Now lets add some scipt to validate this form.
- $(document).ready(function() {
- $('#myform').bootstrapValidator({
- message: 'This value is not valid',
- feedbackIcons: {
- valid: 'glyphicon glyphicon-ok',
- invalid: 'glyphicon glyphicon-remove',
- validating: 'glyphicon glyphicon-refresh'
- },
- fields: {
- name: {
- validators: {
- notEmpty: {
- message: 'Please enter your full name'
- }
- }
- },
- details: {
- validators: {
- notEmpty: {
- message: 'Please enter your details'
- }
- }
- },
- email: {
- validators: {
- notEmpty: {
- message: 'Please enter your email'
- }, emailAddress: {
- message: 'The value is not a valid email address'
- }
- }
- },
- phone: {
- validators: {
- notEmpty: {
- message: 'Please enter your phone no.'
- },
- digits: {
- message: 'The mobile phone number is not valid'
- },
- stringLength: {
- min: 10,
- max: 11,
- message: 'The phone no. must be 10 digits'
- }
- }
- },
- }
- });
- });
Don't forget to add library to validate form.
<script src="http://demo.expertphp.in/js/validator.js"></script>