⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

.:::Refresh a form



elanouar

elanouar
  • profile picture
  • Member

Posted 30 May 2013 - 21:31 PM

Dear All,

Actually I designed a form in which:

 

1-The client uploads a file

2-After uploading the xlsx file the server parse it

3-If there is any mistake into the file I have to refresh the form (reset the window)

4-If there is not any problem the server will fulfill the data base with the extracted content

 

In the 3rd step I tried to use the redirect or the anchor cmds in the callback_after_upload .Unfortunately the form did not refresh after a call to a the same controller by using the previous functions. Thus is there anyone who could help us to under pass this problem.

Thanks in advance for your help.

 

 


davidoster

davidoster
  • profile picture
  • Member

Posted 31 May 2013 - 08:48 AM

I think we need to see your controller in order to be able to help you.

But, in general, since you're in an add state and the uploaded file is wrong just redirect to your_controller/your_function/add and just display an error message, all this within callback_after_upload.


elanouar

elanouar
  • profile picture
  • Member

Posted 01 June 2013 - 07:42 AM

My class :

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class PersonneAdd extends CI_Controller {
 
    function __construct()
    {
        parent::__construct(); 
        
        $this->load->database();
        $this->load->helper('url');
		$this->load->helper('download');
        /* ------------------ */ 
 
        $this->load->library('grocery_CRUD');
        $this->load->model('personne');
    }
 
    public function index()
    {
	     
	        
    }
	
	 public function personneBlocAdd()
    {

		$this->personne->empty_temppersonne(); 
        $this->grocery_crud->set_table('temppersonne');
		$this->grocery_crud->set_relation('idGroupe','groupe','nomGroupe'); 
		
    	$this->grocery_crud->columns('idGroupe','file_url ','upload'); 		
		$this->grocery_crud->display_as('idGroupe','Groupe');
		$this->grocery_crud->display_as('file_url','Chargement du fichier de donn&eacute;es');	
		$this->grocery_crud->display_as('upload','T&eacute;l&eacute;chargement d&#8217;un fichier type');
		$this->grocery_crud->fields('idGroupe','cin','prenom','nom','numTel','dateNaissance','email','Sexe','file_url','upload'); 
		
		/*********************** Default Values ***************************/
		/*************************************************/
		$this->grocery_crud->field_type('cin', 'hidden', '0000000');  
		$this->grocery_crud->field_type('prenom', 'hidden','Test');
		$this->grocery_crud->field_type('nom', 'hidden','Test');
		$this->grocery_crud->field_type('numTel', 'hidden','00000000');
		$this->grocery_crud->field_type('dateNaissance', 'hidden','01/01/2000');
		$this->grocery_crud->field_type('email', 'hidden','Test@test.test');
		$this->grocery_crud->field_type('Sexe', 'hidden','Masculin');
		     	
		/*****************************************************/
		 
		$this->grocery_crud->set_field_upload('file_url','application/controllers/xlsupload'); 		
		$this->grocery_crud->callback_after_upload(array($this,'example_callback_after_upload'));
		

        $this->grocery_crud->callback_add_field('upload',array($this,'add_field_callback_upload'));	   		
		$this->grocery_crud->set_theme('datatables');
		$this->grocery_crud->unset_back_to_list();
		
		/*************************/
		try{
            $output =$this->grocery_crud->render();
           } catch(Exception $e)
		   {
            if($e->getCode() == 14) 
           {
            redirect(strtolower(__CLASS__).'/'.strtolower(__FUNCTION__).'/add');

            }
              else
               {
               show_error($e->getMessage());
                }
           }	  
              $this->_example_output($output);           
    }
	
	function add_field_callback_upload()
{
	 
      return '<a href="'.realpath('null').'/Tempxlsx/personne.xlsx'.'" title="News title">Fichier Exemple</a>';
}
	
	function example_callback_after_upload($files_to_upload,$field_info)
   {
   
    $this->xlsfullarray();
   }
   
   
	public function xlsfullarray()
    {
		$this->load->helper('url');
	  $ctrl=0;
      require_once '/ex/Classes/PHPExcel/IOFactory.php';
 
      $objReader = new PHPExcel_Reader_Excel2007();
      $objReader->setReadDataOnly(true);
      $objPHPExcel = $objReader->load(dirname(__FILE__) . '/xlsupload/e9b50-personne.xlsx' );

      $rowIterator = $objPHPExcel->getActiveSheet()->getRowIterator();


     $array_data = array();
     foreach($rowIterator as $row)
	 {
    $cellIterator = $row->getCellIterator();
    $cellIterator->setIterateOnlyExistingCells(false);  
    if(1 == $row->getRowIndex ()) continue; 
    $rowIndex = $row->getRowIndex ();
    $array_data[$rowIndex] = array('A'=>'', 'B'=>'','C'=>'','D'=>'','E'=>'','F'=>'','G'=>'');
     
    foreach ($cellIterator as $cell) {
        if('A' == $cell->getColumn()){
            $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
        } else if('B' == $cell->getColumn()){
            $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
        } else if('C' == $cell->getColumn()){
            $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
        }  else if('D' == $cell->getColumn()){
            $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
        } else if('E' == $cell->getColumn()){
            $array_data[$rowIndex][$cell->getColumn()] = PHPExcel_Style_NumberFormat::toFormattedString($cell->getCalculatedValue(), 'YYYY-MM-DD');
        }else if('F' == $cell->getColumn()){
            $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
        }else if('G' == $cell->getColumn()){
            $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
        }
		
    }
}

  foreach ($array_data as $cel) 
  {
	
	echo $cel['C'].'<br/>';
	 if (($this->nomcheck($cel['A'])==1)) $ctrl=1;
     if (($this->prenomcheck($cel['B'])==1)) $ctrl=1;  		
 	 if (($this->cincheck($cel['C'])==1)) $ctrl=1;	
     if (($this->numtelcheck($cel['D'])==1)) $ctrl=1;		
     if (($this->is_date($cel['E'])==1)) $ctrl=1;		
     if (($this->VerifierAdresseMail($cel['F'])==1)) $ctrl=1;		
     if (($this->is_sexe($cel['G'])==1)) $ctrl=1;						   
	  
  }
  $ctrl=1; // just to force a redidrection  -------->testing purpose

  
  if ($ctrl==1)
{
  redirect("/PersonneAdd/personneblocadd");             // bug at  this line
	 
							  								  
}
 

}
		
	
    function _example_output($output = null) 
 
    {
        $this->load->view('our_template.php',$output);    
    }
	
	
}
 


davidoster

davidoster
  • profile picture
  • Member

Posted 01 June 2013 - 08:42 AM

I think you redirect is wrong!

redirect("/PersonneAdd/personneblocadd");

It should be redirect("PersonneAdd/personneblocadd");


elanouar

elanouar
  • profile picture
  • Member

Posted 01 June 2013 - 09:44 AM

I tested both of them unfortunately the same error message that appears. :(

 


davidoster

davidoster
  • profile picture
  • Member

Posted 01 June 2013 - 23:21 PM

Read here how to debug your code.

This error occurs well before the callback function.

It could be failing for various reasons. Debug and check the logs.