Welcome Guest, Not a member yet? Register   Sign In
How to import validation rules from file?
#1

[eluser]Leon Stafford[/eluser]
Hi,

Am trying to move my code for multiple forms' config arrays to an external config/settings file.

Should I be using load->config or includes or something else?

My code is below, with a sample config array publicly defined at the top.

If some CI-savvy person could show me how to modify this to call from an external file I'd be grateful.

Code:
<?php
class Save extends Controller {
    public $results = array();
    public $validation_config = array();
    public $shop_validation = array(
               array(
                     'field'   => 'username',
                     'label'   => 'Username',
                     'rules'   => 'trim|required|prep_for_form'
                  ),
               array(
                     'field'   => 'password',
                     'label'   => 'Password',
                     'rules'   => 'trim|required|matches[passconf]|md5'
                  ),
               array(
                     'field'   => 'passconf',
                     'label'   => 'Password Confirmation',
                     'rules'   => 'trim|required'
                  ),  
               array(
                     'field'   => 'email',
                     'label'   => 'Email',
                     'rules'   => 'trim|required|valid_email'
                  )
            );
            
    function Save()
    {
        parent::Controller();
        $this->load->helper(array('form', 'url','html'));
        $this->load->library('form_validation');
    }
    
    function index()
    {    
        
        $this->load->view('upload_form');    
    }

    function file_upload()
    {
        
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '3000';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        $this->load->library('upload', $config);
        $number_of_files = 4;
        
        for ($file_counter = 0; $file_counter < $number_of_files; $file_counter +=1){
            $this->upload->initialize($config);
            if ( ! $this->upload->do_upload('userfile'.$file_counter))
            {
                $this->results['result'.$file_counter]['error'] = array($this->upload->display_errors('<p style="color:red;">', '</p>'));
                $this->results['result'.$file_counter]['success'] = array('');
            }    
            else
            {
                $this->results['result'.$file_counter]['success'] = array($this->upload->data());
                $this->results['result'.$file_counter]['error'] = array('');
            }
        }
        
    }
        
    function validate_form()
    {
        $this->form_validation->set_error_delimiters('<p style="color:red;">', '</p>');
        $this->form_validation->set_rules($this->validation_config);        
                
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('upload_form', $this->results);
        }
        else
        {
            $this->load->view('form_success');
        }
        
    }
    function save_shop()
    {
    $this->file_upload();
    $this->validation_config = $this->shop_validation;
    $this->validate_form();
    }
}
?&gt;


Messages In This Thread
How to import validation rules from file? - by El Forum - 02-09-2009, 07:17 PM
How to import validation rules from file? - by El Forum - 02-09-2009, 07:35 PM
How to import validation rules from file? - by El Forum - 02-09-2009, 07:53 PM
How to import validation rules from file? - by El Forum - 02-09-2009, 08:07 PM
How to import validation rules from file? - by El Forum - 02-09-2009, 08:11 PM
How to import validation rules from file? - by El Forum - 02-09-2009, 08:52 PM
How to import validation rules from file? - by El Forum - 05-06-2009, 02:25 PM



Theme © iAndrew 2016 - Forum software by © MyBB