⚠ 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

[ANSWERED] Adding extra field that doesn't exist in form at the callback_insert or callback_update doesn't work



web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 02 May 2012 - 06:02 AM

Well there is a solution for this.
That's why I created the type "invisible" field. So for example if you have:


$crud->fields('field1','field2','field3');
$crud->callback_before_insert(array($this,'test_callback'));


and :


function test_callback($post_array){
$post_array['field4'] = 'test';
return $post_array;
}


This will NOT works unless you add the invisible field so you have to do it like this:


$crud->fields('field1','field2','field3','field4');
$crud->change_field_type('field4','invisible');
$crud->callback_before_insert(array($this,'test_callback'));


So this WILL WORK as you expected and without showing the field "field4" in the form.

The "invisible" field is made for this exact reason. I know that it is undocumented that's why I add it here.

cgomez

cgomez
  • profile picture
  • Member

Posted 21 November 2013 - 16:39 PM

Please you can help me.

I want to insert into the field ¨codigo¨  the concatenated values ​​of the month  and year is possible

$this->grocery_crud->set_table('tb_plan');
                        
                         $this->grocery_crud->required_fields('MaximaDemandaPlan','PlanConsumoActivo','PlanConsumoReactivo','idMes','idYear','idEntidad');
              
                         $this->grocery_crud->display_as('PlanConsumoActivo','Consumo Activo');
                   $this->grocery_crud->display_as('PlanConsumoReactivo','Consumo Reactivo');
                  $this->grocery_crud->display_as('MaximaDemandaPlan','Maxima Demanada');
                        
                        $this->grocery_crud->set_subject('Plan');
                        
                       $this->grocery_crud->set_relation('idMes','tb_mes','Nombre');
                      
                        
                       $this->grocery_crud->set_relation('idEntidad','tb_Entidad','NombreEntidad');
                        $this->grocery_crud->display_as('idEntidad','Nombre de la Entidad');
                        
                       $this->grocery_crud->set_relation('idYear','tb_Year','Year');
                        $this->grocery_crud->display_as('idYear','Año');
                       
$this->grocery_crud->callback_before_insert(array ($this,'generar_codigo'));
 $this->grocery_crud->change_field_type('codigo','invisible');
                                
        $output = $this->grocery_crud->render();

        $this->_example_output($output);

 

and the callaback function is :

    function generar_codigo($post_array){
            $f=  $post_array['Nombre'];
            $a=$pos_array['year'];
            $cont=$f.$a;
            
           /* $a=$pos_array['Año'];*/
          //  $con=$f.$a;
            $post_array['codigo']=$cont;
          
          return $post_array;
    }