Return to Snippet

Revision: 20513
at November 17, 2009 12:27 by djenniex


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

class Form_test extends Controller 
{
	/**
	 * Constructor
	 *
	 * @return name
	 * @access public
	 */    
    public function __construct()
    {
        parent::Controller();
    }

    /**
     *
     *
     * @access public
     */    
    public function index()
    {
		$data = array();
        $this->form_validation->set_rules('user_file', 'User File', 'file_required|valid_file_extension[doc|docx|pdf]');
        $this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
        
        if ($this->form_validation->run($this))
        {
            $first_name = $this->input->post('first_name');
            
            $this->load->library('upload');
            $this->upload->initialize(array(
                'upload_path'   => './uploads/',
                'allowed_types' => 'doc|docx|pdf',
                'overwrite'     => TRUE
            ));
            if ($this->upload->do_upload('user_file') === FALSE)
            {
                $upload_errors = $this->upload->display_errors();
            }
            else
            {  
                $data['success'] = TRUE;
                $data['upload_data'] = var_export($this->upload->data(), TRUE);
            }
        }
        $data['form_errors']     = validation_errors();
        $data['user_file']       = set_value('user_file', '');
        $data['user_file_error'] = form_error('user_file');
        $data['file_info']       = var_export($_FILES, TRUE);
        $this->load->view('form_test', $data);
    } 
}

/* End of file name.php */
/* Location: ./system/application/controller/name.php */

Initial URL

                                

Initial Description
Test controller for custom Form_validation class

Initial Title
Form Test Controller

Initial Tags
form

Initial Language
PHP