Jump to content

callback_after_update + condition + $post_array

callback_after_updatecondi condition post_array

  • Please log in to reply
2 replies to this topic

#1 mcl



  • Members
  • Pip
  • 4 posts

Posted 30 September 2013 - 10:25 PM



I have a problem evaluating a condition. I have if((empty($post_array['Date_Deb'])) && ($post_array['Etat'] == '3')) as condition and Date_Deb is being updated even if Date_Deb is NOT empty.

The second part of the condition is evaluated correctly. If Etat is not equal to 3, Date_Deb is not updated.

You can see my code below.

Note that Date_Deb is set as a read only field but removing that constraint don't change anything. It seems GC is seeing $post_array['Date_Deb'] on update even if it had been previously filled in using the function.


Can you tell me what is wrong please?

function st3() {
                  $crud = new grocery_CRUD();
            $crud->columns('ID','Nom_agt','Date_Rem','Date_Deb', 'Etat');
            $crud->fields('Nom_agt','Date_Rem','Date_Deb', 'Etat');
            $crud->edit_fields('Nom_agt','Date_Deb', 'Etat');
           $crud->field_type('Date_Deb', 'readonly');
            $crud->callback_after_update(array($this, 'update_date_debriefe'));
            $output = $crud->render();
function update_date_debriefe($post_array,$primary_key)
if((empty($post_array['Date_Deb'])) && ($post_array['Etat'] == '3'))  {
    $date_debriefe = array("ID" => $primary_key,"Date_Deb" => date('2013-07-01'));
    $this->db->update('t3',$date_debriefe,array('ID' => $primary_key));
   return true;

#2 mcl



  • Members
  • Pip
  • 4 posts

Posted 30 September 2013 - 11:48 PM

I have found a way of doing it but i need to query db on each update and this add some execution time.

Any other way to store the content of Date_Deb in a variable before evaluating it ?

function update_date_debriefe($post_array,$primary_key)
                     ->where('ID', $primary_key);
            $db = $this->db->get();
            $row = $db->row(0);
            $DD = $row->Date_Deb;

if((empty($DD)) && ($post_array['Etat'] == '3'))  {
    $date_debriefe = array("ID" => $primary_key,"Date_Deb" => date('2017-01-10'));
    $this->db->update('t3',$date_debriefe,array('ID' => $primary_key));
   return $post_array;

#3 davidoster


    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 01 October 2013 - 04:15 AM


Why don't you debug  / echo / inspect see the actual value that the field has on the $post_array after update.

Obviously there is something different there, otherwise it should evaluate the whole condition to true.


UPDATE: On your last post you reassign the same value as before of the ID. Isn't this autonumbered? Maybe this generates some problems?

Why don't you update just the date field?

Edited by davidoster, 01 October 2013 - 04:22 AM.



rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---



David Oster aka George Pasparakis,

Also tagged with one or more of these keywords: callback_after_updatecondi, condition, post_array

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users