Giter VIP home page Giter VIP logo

codeigniter-form-validation-extension's Introduction

Officially DEPRECATED

Reason: There is Codeigniter 4 with a perfect validation library :)

Codeigniter Form Validation Extension

This is a extension library of Form_validation

Features

  • Avoid resend POST vars on refresh form page (Don't worry about F5)
  • Get Flashmessage for Errors
  • Get Flashmessage for Success
  • Ajax Validation Response
  • Customize Ajax success response
  • Customize Success Message
  • Extends Validators (Easy and fast)

Installation

  1. Download the latest release
  2. Copy the folder FormValidation/ and the file MY_Form_validation.php to your Codeigniter folder application/libraries
application/
-- libraries/
---- FormValidation/
---- MY_Form_validation.php

How to use

Without ajax

The Form

Create a view file (using the functions to repopulate) The Form view

Create the controller method: The Form controller method

The validation

Create a controller method for validate your data (and save in database) The post controller method

With Ajax

The Form

Requirements: The JQuery plugin formHelper

Create a view file: The Form view

Create the controller method: The form controller

The validation

The post controller method

Extending validations

Create the validator function

Open the file FormValidation/validators.php and create your function.

validators.php

/*This example is for Brasil Zip code*/
function zipcode($value)
{
    return ((preg_match('/^[0-9]{5,5}([-]?[0-9]{3,3})?$/', $value))===1);
}

Done, now you can use the function in your validation rules.

How to use

$this->form_validation->set_rules('zipcode', 'Zip code', 'required|zipcode', array('zipcode'=>'Escreva um cep valido'));

Class reference

setSuccessMessage($text)

Setting the success message

Parameters:

  • string $text - Success message

setSuccessDelimiters($open, $close)

Sets the default prefix and suffix for success message

Parameters:

  • string $open - Open delimiter
  • string $close - Close delimiter

setRedirect($redirect)

Redirect after execute validation

Parameters:

  • string $redirect - URI/URL to redirect

repopulateAllExcept(array $array)

Exclude Fields to re-populate

Parameters:

  • array $array Associative array with the fields to exclude

validate(callable $success_cb, callable $error_cb = NULL)

Run the validation

Parameters:

  • callable $success_cb Successfull callback
  • callable $error_cb Error callback

getMessage()

Get the validation message

Return: string The message (Html code)

getValues()

Get Form Values (JSON string) from flashdata

Return: string - Json string

setMessageTemplate($template, $classType = NULL)

Setting the message template

Parameters:

  • string $template - Template string
  • array $classType - (Optional) CSS Class to replace in template. Examples: ['class-error'=>'alert-danger', 'class-success'=>'alert-success']. Defaults: ['class-error'=>'error', 'class-success'=>'success']

addSuccessJsonVar($key, $value)

Add variable on success json response (Only for ajax request)

Parameters:

  • string $key - Key name
  • string $value - Value

Helpers included

setValue($field, $default = '')

Display the value for input field. Use in a view file.

Parameters:

  • string $field - Input name
  • string $default - (Optional) Default value

setChecked($field, $value)

Display 'checked' for input type checkbox and radio button. When the value is present in form values, display "checked". Use in a view file.

Parameters:

  • string $field - Input name
  • string $value - This value is setting? .. So, Checked

setSelected($field, $value)

Display 'selected' for input select(comobobox). When the value is present in form values, display "selected". Use in a view file.

Parameters:

  • string $field - Input name
  • string $value - This value is setting? .. So, Selected

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.