I have some script for image upload and I’m using it with form validation. So this is the code:
$this->form_validation->set_rules('name','Name','required|max_length[30]|xss_clean');
$this->form_validation->set_rules('desc','Description','required|xss_clean');
if ($this->form_validation->run() == TRUE)
{
$config = array(
'allowed_types' => 'jpg|jpeg|png|gif',
'upload_path' => path/to/folder,
'max_size' => 3000,
'max_height' => 1024,
'max_width' => 1024,
'remove_spaces' => TRUE
);
$this->load->library('upload', $config);
if ($this->upload->do_upload())
{
//code for insert this data into database
}
else
{
//code for FALSE the form validation and error message with flashdata
}
Now I would like to false form if there is some error with image upload. I want to do this like the error of some field (if it’s empty), to get data of post variables back (for field’s content).
What’s the best way to do that?
The
elsecondition of the$this->form_validation->run()and$this->upload->do_upload()should be similiar.form validation:
file upload:
The ‘form’ view is the one loaded initially. It can have a div of this sort: