• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom Validation Function

#8
(09-22-2015, 06:52 AM)kilishan Wrote: A slightly more "proper" way to do it would be to extend the Form_validation library in a MY_Form_validation file. Add the functions to that, and then you should be able to use it like:


Code:
$this->form_validation->set_rules('input', 'lang:', 'trim|required|my_validation' );

I would advise you to use this approach.

First of all, it keeps all your code related to form validation together.
Second, you can easily override the default rule methods with your own.

Here is an example of a MY_Form_validation.php:

PHP Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * My Form validation
 * 
 * This class extends the CodeIgniter Form validation library.
 */

class MY_Form_validation extends CI_Form_validation {
 
 
   /**
     * __get
     *
     * Enables the use of CI super-global without having to define an extra variable.
     *
     * @access public
     * @param $var
     * @return mixed
     */
 
   public function __get($var) {
 
       return get_instance()->$var;
 
   }

 
   public function my_validation($str) {
 
       // Do whatever you need to do
 
   }
 

Reply


Messages In This Thread
Custom Validation Function - by ardavan - 09-22-2015, 06:28 AM
RE: Custom Validation Function - by kilishan - 09-22-2015, 06:52 AM
RE: Custom Validation Function - by ardavan - 09-24-2015, 06:10 PM
RE: Custom Validation Function - by ardavan - 09-30-2015, 02:15 AM
RE: Custom Validation Function - by Martin7483 - 09-30-2015, 02:37 AM
RE: Custom Validation Function - by ardavan - 09-30-2015, 03:13 AM
RE: Custom Validation Function - by Martin7483 - 09-30-2015, 03:39 AM
RE: Custom Validation Function - by Martin7483 - 09-30-2015, 07:22 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.