Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Multiple Validations
#1

[eluser]Buso[/eluser]
How can I do form_validation->run() many times, and print different validation_errors() ?

I'm trying to make multiple inserts and validate them in the model ( tried to do something like jamie rumbelow did with his MY_Model ), but the problem is that after the first validation, all the other validations get the same result and errors as the first one. I'm not sure if I missed something, or this is how form_validation library handles this (only one form validation possible), and I have to find a way to bridge this and make it have other behaviour.

Any ideas? Anyone else validates the input in the model?

-------

Solution:

Code:
<?php

class MY_Form_validation extends CI_Form_validation {
    
    /**
     * Re-initialize the vars.
     *
     * @author Horacio J. Peña
     */
    public function initialize($rules = array()) {
      
        $this->_field_data            = array();    
        $this->_config_rules            = array();
        $this->_error_array            = array();
        $this->_error_messages        = array();    
        $this->_error_prefix            = '<p>';
        $this->_error_suffix            = '</p>';
        $this->error_string            = '';
        $this->_safe_form_data         = FALSE;
        
        $this->CI =& get_instance();
        
        // Validation rules can be stored in a config file.
        $this->_config_rules = $rules;
        
        // Automatically load the form helper
        $this->CI->load->helper('form');

        // Set the character encoding in MB.
        if (function_exists('mb_internal_encoding'))
        {
            mb_internal_encoding($this->CI->config->item('charset'));
        }
        
    }
    
}

// END OF PHP FILE

just use $this->form_validation->initialize() and it will re-initialize everything




Theme © iAndrew 2016 - Forum software by © MyBB