Whole page should consist a single form and form validation can be used to validate the data. Then the submit button of the form can be used as the file upload button. This prevents page from reloading.
Study more on this using the following links.
Form Validation
File Uploading
The following code contains a sample of implementing the above theory.
//form in view
<?php echo $formerror;?>
<?php echo form_open_multipart(base_url('
<input type="file" name="userfile" size="20" />
<input type="text" id="TitleOfFile" name="TitleOfFile" value="" size="70">
<input type="submit" value="upload" />
<?php echo $uploaderror;?>
</form>
//controller method
controller
function do_upload()
{
//echo 'true';
$this->load->helper(array('
$this->load->library('form_
$this->form_validation->set_
if ($this->form_validation->run() == FALSE)
{
//echo 'form validation false';
$formerror="form validation false";
$navtab='includes/navigation';
$footer='footer';
$home='Ongoing_conference';
$login_view='includes/login_
$registration_view='includes/
$paras = array('site_navigations' => $navtab, 'footer' => $footer, 'content' => $home, 'login_view'=>$login_view, 'registration_view'=>$
$this->load->view('includes/
}
else if($this->form_validation->
{
//echo 'form validation true';
$config['upload_path'] = './assets/upload/materials/';
$config['allowed_types'] = 'docx|pdf';
$config['max_size'] = '2000';
$config['file_name'] = "yas";
$config['overwrite'] = TRUE;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$uploaderror = $this->upload->display_errors(
$navtab='includes/navigation';
$footer='footer';
$home='Ongoing_conference';
$login_view='includes/login_
$registration_view='includes/
$paras = array('site_navigations' => $navtab, 'footer' => $footer, 'content' => $home, 'login_view'=>$login_view, 'registration_view'=>$
$this->load->view('includes/
//echo $uploaderror;
}
else
{
$uploaderror='file is uploaded now with correct form validation !';
$navtab='includes/navigation';
$footer='footer';
$home='Ongoing_conference';
$login_view='includes/login_
$registration_view='includes/
$paras = array('site_navigations' => $navtab, 'footer' => $footer, 'content' => $home, 'login_view'=>$login_view, 'registration_view'=>$
$this->load->view('includes/
}
}
}
No comments:
Post a Comment