Welcome Guest, Not a member yet? Register   Sign In
Validation file input and text input
#1

[eluser]cyberjunkie[/eluser]
Has anyone successfully validated file and text inputs from a multipart form? I tried many solution but nothing seems to work. Please share you experience.

Code:
function create() //create new post
{          
    $this->form_validation->set_rules('content', 'Entry', 'trim|required|xss_clean');
    $this->form_validation->set_rules('category_id', 'Category', 'trim|required|xss_clean|integer');

    //Text input fields
    if ($this->form_validation->run() == FALSE)
    {
        $this->load->view('new_post');
    }      
    else
    {
            $config['upload_path'] = './uploads/posts/';
            $config['allowed_types'] = 'jpg|png';              
            $config['max_size'] = '800'; //in KB

            $this->load->library('upload', $config);

            //File Upload
            if (! $this->upload->do_upload())
            {
                $upload_error['upload_error'] = array('error' => $this->upload->display_errors());

                $this->load->view('my_view', $upload_error);

                return FALSE;
            }

             //Add to database
             $data = array (
               'user_id' => $this->tank_auth->get_user_id(),
               'category_id' => $this->input->post('category_id'),
               'content' => $this->input->post('content')
             );

             $this->Posts_model->create_post($data);

             $this->session->set_flashdata('success', 'Post_added!');
             redirect('posts');
    }      

}


Messages In This Thread
Validation file input and text input - by El Forum - 07-09-2012, 11:17 AM
Validation file input and text input - by El Forum - 07-10-2012, 01:23 AM
Validation file input and text input - by El Forum - 07-10-2012, 02:11 AM
Validation file input and text input - by El Forum - 07-10-2012, 12:03 PM
Validation file input and text input - by El Forum - 07-10-2012, 12:22 PM
Validation file input and text input - by El Forum - 07-11-2012, 01:44 AM
Validation file input and text input - by El Forum - 07-11-2012, 11:05 AM
Validation file input and text input - by El Forum - 07-11-2012, 02:29 PM
Validation file input and text input - by El Forum - 07-11-2012, 02:53 PM
Validation file input and text input - by El Forum - 07-11-2012, 02:58 PM
Validation file input and text input - by El Forum - 07-12-2012, 01:50 AM
Validation file input and text input - by El Forum - 07-12-2012, 02:17 AM
Validation file input and text input - by El Forum - 07-13-2012, 10:48 AM



Theme © iAndrew 2016 - Forum software by © MyBB