Giter Site home page Giter Site logo

codeigniter-jquery-validator's Introduction

CodeIgniter jQuery validator library

This is very simple library which generates Javascript code for forms validation

It generates validation rules and custom error messages for jQuery Validation Plugin

Usage

  1. Load library in your controller.
$this->load->library('jquery_validation');
  1. Set CodeIgniter standard validation rules ( The same rules format which has form_validtion library ).
$rules = array(
                array(
                     'field'   => 'username',
                     'label'   => 'Username',
                     'rules'   => 'required|min_length[2]'
                  ),
               array(
                     'field'   => 'email',
                     'label'   => 'Email',
                     'rules'   => 'required|valid_email'
                  ),
               array(
                     'field'   => 'url',
                     'label'   => 'URL',
                     'rules'   => 'required'
                  )
           );
  1. Set error messages.
$messages = array(
                 'username'  => array( 'required'    => "Username is required",
                                       'min_length'  => "Please enter more then 2 char"
                                     ),
                                     
                 'email'     => array( 'required'    => "Email is required",
                                       'valid_email' => "Please enter valid email"
                                     )
                 );
  1. Apply validation rules and messages to library.
$this->jquery_validation->set_rules($rules);
$this->jquery_validation->set_messages($messages);
  1. Generate Javascript validation code.
// pass css selector for your form to run method

$validation_script = $this->jquery_validation->run('#registration_form');

// echo $validation_script in your <script> tag
  1. Enjoy :-)

codeigniter-jquery-validator's People

Contributors

gurik avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.