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

[eluser]Leon Stafford[/eluser]
Thanks again!

Here's what I have if it helps anyone:

Main class:
Code:
<?php
class Admin extends Controller {
    public $results = array();
    public $validation_config = array();
    public $upload_config = array();
    function Admin()
    {
        parent::Controller();
        $this->load->helper(array('form', 'url','html'));
        $this->load->library('form_validation');
    }
    
    function index()
    {    
        
        $this->load->view('upload_form');//change to admin_top
    }

    function file_upload()
    {

        $this->load->library('upload', $this->upload_config);
        $number_of_files = 4;
        
        for ($file_counter = 0; $file_counter < $number_of_files; $file_counter +=1){
            $this->upload->initialize($this->upload_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>');
                
        if ($this->form_validation->run($this->validation_config) == FALSE)
        {
            $this->load->view('upload_form', $this->results);
        }
        else
        {
            $this->load->view('form_success');
        }
        
    }
    function save()
    {
    $area_to_save = $this->uri->segment(3);
    switch ($area_to_save)
    {
        case "shop":
            $this->config->load('upload_settings');
            $this->upload_config = $this->config->item('shop_upload_settings');    
            $this->file_upload();
            $this->validation_config = 'shop_validation';
            $this->validate_form();
        break;
        case "event":
            $this->config->load('upload_settings');
            $this->upload_config = $this->config->item('event_upload_settings');
            $this->file_upload();
            $this->validation_config = 'event_validation';
            $this->validate_form();
        break;
        default:
            echo "no save target specified";
        break;
    }
    }
}
?&gt;

form_validation config:
Code:
&lt;?php
$config = array(
    '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'
                          )
                    ),
    'event_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'
                          )
                    )                
);                    
?&gt;

upload_settings config:
Code:
&lt;?php
$config = array(
    'shop_upload_settings'=>array(
                                     'upload_path'   => './uploads/shop/',
                                     'allowed_types'   => 'gif|jpg|png',
                                     'max_size'   => '3000',
                                     'max_width'   => '1024',
                                     'max_height'   => '768'
                                  ),
    'event_upload_settings'=>array(
                                     'upload_path'   => './uploads/event/',
                                     'allowed_types'   => 'gif|jpg|png',
                                     'max_size'   => '3000',
                                     'max_width'   => '1024',
                                     'max_height'   => '768'
                                  )                              
        );                    
?&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