⚠ 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

multiple save



dux

dux
  • profile picture
  • Member

Posted 19 July 2013 - 11:39 AM

first of all i would like to thank you for the great job you've done and for sharing this for free.. i encountered this problem when adding a record. when i click on the save and close button, the record is save in the database, close the form and go back to the list. the record is displayed on the list but the problem is, the record has been saved a couple of times.. attached is the print screen on the output.. hope somebody can help me on this.. thanks in advance


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 19 July 2013 - 11:48 AM

Hi Dux,

 

Welcome to Grocerycrud Forum. Can you paste in your piece of code for the same so we can have a look at what is happening and why it is happening. Please paste the code of the controller method and a few callbacks if at all you making.


dux

dux
  • profile picture
  • Member

Posted 19 July 2013 - 12:58 PM

hi amit shah and thank you for the quick response.. here's is my controller..

 

 function doc_management() {
  $crud = new grocery_CRUD();
  
  $crud->set_table('tbl_doc_info');
  $crud->set_subject('Document')
       ->columns('divID','subject','author','dt_pub','origin','no_of_cy','classID','resID','mediumID','timeID','reten_pr')
             ->display_as('divID','Location')
    ->display_as('subject','Title/Subject')
    ->display_as('author','Author')
    ->display_as('dt_pub','Date Published')
    ->display_as('origin', 'Received From')
    ->display_as('no_of_cy','No. of Copies')
    ->display_as('classID','Classification')
    ->display_as('resID','Restriction')
    ->display_as('mediumID','Medium')
    ->display_as('timeID','Time Value')
    ->display_as('reten_pr','Retention Period');
  $crud->fields('divID','subject','author','dt_pub','origin','no_of_cy','classID','resID','mediumID','timeID','reten_pr','attachment');
 
  $crud->required_fields('divID','subject','origin','classID');
  $crud->set_field_upload('attachment','assets/uploads/files');
  
  $crud->set_relation('divID','ref_division','acronym');
  $crud->set_relation('classID','ref_classification','class_name');
  $crud->set_relation('resID','ref_restriction','res_name');
  $crud->set_relation('mediumID','ref_medium','description');
  $crud->set_relation('timeID','ref_time_value','description');
  
  $crud->callback_add_field('resID', array($this, 'empty_restrictions_dropdown_select'));
  $crud->callback_edit_field('resID', array($this, 'empty_restrictions_dropdown_select'));
  $crud->callback_column('subject', array($this, 'column_as_link_doc'));
 
  $output = $crud->render();
  
  //Dependent Dropdown Setup
  $dd_data = array(
   //Get the state of the current page
   'dd_state' =>  $crud->getState(),
   
   //Setup dropdowns. Parent field items comes first in array
   //Child field items need to follow in order
   'dd_dropdowns' => array('classID','resID'),
   
   //Setup URL POST for each child. List in order as per above
   'dd_url' => array('', site_url().'/file_mngr/get_restriction/'),
   
   //Loader that gets displayed next to the parent dropdown while the child loads
   'dd_ajax_loader' => base_url().'ajax-loader.gif'
  );
  
  $output->dropdown_setup = $dd_data;
   
  $this->_pg_view($output);
 }

 

 

and these are my callbacks...

 

 function column_as_link_doc($value,$row) {
  return "<a href='".site_url('file_mngr/doc_management/edit/'.$row->docID)."'>$value</a>";
 }

 

 //CALLBACK FUNCTIONS
 function empty_restrictions_dropdown_select()
 {
  //CREATE THE EMPTY SELECT STRING
  $empty_select = '<select name="resID" class="chosen-select" data-placeholder="Select Restriction" style="width: 300px; display: none;">';
  $empty_select_closed = '</select>';
  
  //GET THE ID OF THE LISTING USING URI
  $listingID = $this->uri->segment(4);
  
  //LOAD GCRUD AND GET THE RESTRICTION VALUE
  $crud = new grocery_CRUD();
  $state = $crud->getState();
  
  //CHECK FOR A URI VALUE AND MAKE SURE ITS ON THE EDIT STATE
  if(isset($listingID) && $state == "edit") {
   //GET THE STORED RESTRICTION VALUE ID
   if ($crud->set_subject('Document')) {
    $this->db->select('classID, resID')
      ->from('tbl_doc_info')
      ->where('docID', $listingID);
   }
   elseif($crud->set_subject('Record')) {
    $this->db->select('classID, resID')
      ->from('tbl_rec_info')
      ->where('recID', $listingID);
   }
   
   $db = $this->db->get();
   $row = $db->row(0);
   $classID = $row->classID;
   $resID = $row->resID;
   
   //GET THE RESTRICTION VALUE PER CLASSIFICATION ID
   $this->db->select('*')
      ->from('ref_restriction')
      ->where('classID', $classID);
   $db = $this->db->get();
   
   //APPEND THE OPTION FIELDS WITH VALUES FROM THE RESTRICTION VALUE PER THE CLASSIFICATION ID
   foreach($db->result() as $row):
    if($row->resID == $resID) {
     $empty_select .= '<option value="'.$row->resID.'" selected="selected">'.$row->res_name.'</option>';
    } else {
     $empty_select .= '<option value="'.$row->resID.'">'.$row->res_name.'</option>';
    }
   endforeach;
   
   //RETURN SELECTION COMBO
   return $empty_select.$empty_select_closed;
  } else {
   //RETURN SELECTION COMBO
   return $empty_select.$empty_select_closed; 
  }
 }
  
 //GET JSON OF RESTRICTION VALUE
 function get_restriction() {
  $classID = $this->uri->segment(3);
  
  $this->db->select("*")
     ->from('ref_restriction')
     ->where('classID', $classID);
  $db = $this->db->get();
  
  $array = array();
  foreach($db->result() as $row):
   $array[] = array("value" => $row->resID, "property" => $row->res_name);
  endforeach;
  
  echo json_encode($array);
  exit;
 }


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 19 July 2013 - 13:38 PM

Hmm.. it seems to be preety normal code.. it should not be having this trouble unless you are managing it to click the save and close button more than once.. is it happening only with save and close .. or even with just single save click? And is it happening always or it just happened up once or what?


dux

dux
  • profile picture
  • Member

Posted 19 July 2013 - 14:06 PM

yes only with save and close button.. the weird thing is that, sometimes it saves the record twice, and sometimes it saves the record 4 times


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 19 July 2013 - 14:12 PM

well.. try it with a tabbing up to the button and pressing single space / enter .. what your mouse would have been playing around would be purely double clicks that gets registered for action. Also check in the firebug how many calls to insert / save are going .. if more then one, then it would be of clicks. Also want to know if you have tweeked up the add / edit form? If so, check in the code out there as what it possibly playing around with the same?


dux

dux
  • profile picture
  • Member

Posted 19 July 2013 - 14:49 PM

i did checked with firebug already and there's only 1 instance of insert..

 

with regards to the add/edit, on the .php, 1 just added an "include" just to add some aesthetics and for the js, i removed some lines in the "goToList function" just to remove the message when you press the cancel button.. i even tried to overwrite my php and js files with the original file but still no luck..


dux

dux
  • profile picture
  • Member

Posted 19 July 2013 - 15:06 PM

ok.. i figured it out.. i tried to backtrack all my revisions before i had this problem.. and sorry i didnt mention this out coz i thought it has nothing to do with the way my save and close button is behaving.. i have this code..

 

 function _pg_view($output = null) {
  $crud = new grocery_CRUD();

  $state = $crud->getState();
  
  $this->load->view('blocks/header');
  
  if($state == "add" || $state == "edit") {
   $this->load->view('blocks/toolbar_add_edit');
   $this->load->view('file_mngr_add_edit',$output);   
  }
  else {
   $this->load->view('blocks/toolbar');
   $this->load->view('file_mngr_view',$output);
  }
    }

 

i have different views for my list and if im on edit/add mode that's why i did this.. but when i change the above code like this..

 

function _pg_view($output = null) {
     $this->load->view('blocks/header');
     $this->load->view('blocks/toolbar');
     $this->load->view('file_mngr_view',$output);
}

 

...my save and close button works perfectly as ecpected but my problem now is that my dependent dropdown list is not working.. the child dropdown doesnt display anything


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 19 July 2013 - 15:13 PM

Do you get any javascript error check the same in firebug.. check if on dropdown change, there is a call being made or not!!


dux

dux
  • profile picture
  • Member

Posted 19 July 2013 - 15:42 PM

304 not modified.. what does it mean?


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 19 July 2013 - 17:19 PM

well.. may not be at time of generation of the page but when you change / select a particular option from first dropdown .. 304 as status means it is not modified and hence wa restored directly from client cache .. and not fetched from server end.


dux

dux
  • profile picture
  • Member

Posted 20 July 2013 - 03:48 AM

thanks amit.. i really appreciate your time