PHP code example of bllim / laravel-to-jquery-validation

1. Go to this page and download the library: Download bllim/laravel-to-jquery-validation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bllim / laravel-to-jquery-validation example snippets


    'providers' => array(
        ...
        'Bllim\LaravelToJqueryValidation\LaravelToJqueryValidationServiceProvider',
    ),

$ php artisan config:publish bllim/laravel-to-jquery-validation
$ php artisan asset:publish bllim/laravel-to-jquery-validation

    $rules = ['name' => 'l' => 'foo/bar', 'method' => 'put'), $rules);
    Form::text('name');
    Form::text('email');
    Form::text('birthdate');
    Form::close(); // don't forget to close form, it reset validation rules
    
    // in controller or route
    $rules = ['name' => 'orm::open(array('url' => 'foo/bar', 'method' => 'put'), $rules);
    // some form inputs
    Form::close();

    $rules = ['age' => 'numeric|max'];

class UserController extends Controller {
    
    public static $createValidation = ['name' => 'tCreate()
    {
        Form::setValidation(static::$createValidation);
        return View::make('user.create');
    }

    public function postCreate()
    {
        $inputs = Input::only(static::$createColumns);
        $rules = static::$createValidation;

        $validator = Validator::make($inputs, $rules);

        if($validator->fails())
        {
            // actually withErrors is not really neccessary because we already show errors at client side for normal users
            return Redirect::back()->withErrors($validator);
        }

        // try to create user

        return Redirect::back()->with('success', 'User is created successfully');
    }
}

<!DOCTYPE html>
<html lang="en">
    <head>
      <meta charset="utf-8">
      <title>Laravel to Jquery Validation</title>
    </head>
    <body>
    
        {{ Form::open(array('url'=>'create', 'method'=>'post')) }}
        {{ Form::text('name') }}
        {{ Form::text('username') }}
        {{ Form::email('email') }}
        {{ Form::number('age') }}
        {{ Form::close() }}

        <script src="{{ asset('js/jquery-1.10.2.min.js') }}"></script>
        <script src="{{ asset('js/jquery.validate.min.js') }}"></script>
        <script src="{{ asset('js/jquery.validate.laravel.js') }}"></script>
        <script type="text/javascript">
        $('form').validate_popover({

            highlight: function(element) {
              jQuery(element).closest('.form-group').removeClass('has-success').addClass('has-error');
            },
            success: function(element) {
              jQuery(element).closest('.form-group').removeClass('has-error');
            },
            events   : 'submit',
            selector : 'input[type!=submit], select, textarea',
            callback : function( elem, valid ) {
                if ( ! valid ) {
                    $( elem ).addClass('error');
                }
            }
          });
        </script>
    </body>
</html>