• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
External functions in form_validation.php file

#2
U need to extend form_validation library


in application library create MY_Form_validation.php


PHP Code:
class MY_Form_validation extends CI_Form_validation {
    
    public function 
__construct()
    {
        
parent::__construct();
    }
}


public function 
custom_rule($input){
 
 $CI $get_instance();
$CI->load->model('custom_model');
$result $CI->custom_model->validate_input($input);

return 
$result //true if validated else false;



then add in config.php

PHP Code:
$config = array(
'user_input_rules' => (
 
   array(
 
       'field'  => 'usuario',
 
       'label'  => 'Nombre de usuario',
 
       'rules'  => 'trim|required|max_length[12]|custom_rule',
 
       'errors' => array(
 
                       'is_unique' => 'El nombre de usuario ya está en uso.'
 
                   )
 
   ),    array(
        'field'  => 'usuario2',
        'label'  => 'Nombre de usuario2',
        'rules'  => 'trim|required|max_length[12]|custom_rule',
        'errors' => array(
                        'is_unique' => 'El nombre de usuario ya está en uso.'
                    )
    )
 
   
); 

in controller method:

PHP Code:
public function user_input(){
$this->load->library('form_validation'); // codeigniter will automaticly load your MY_Form_validation.php
$result $this->form_validation->run('user_input_rules');


in application/language/yourlang/form_validation.php 

you can set error message text
Reply


Messages In This Thread
RE: External functions in form_validation.php file - by neuron - 05-01-2017, 07:00 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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