⚠ 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

Date of creation and change



kris
  • profile picture
  • Member

Posted 26 May 2017 - 08:51 AM

I had on all my table creation user, date of creation and change user and change date

 

this information was display only

 

- How can I put a field display only or protected input on a form. I didn't find it

 

- How can I put value for exemple user code in a field before the creation and before update


darkstalker
  • profile picture
  • Member

Posted 26 May 2017 - 11:23 AM

1) $crud->field_type('field_name','readonly');

 

2)

 

if you want to show the user_id before the creation but not allow to modify it you need to add this code:

 

if ($operation == 'add' || $operation == 'insert' || $operation == 'insert_validation') {

$crud->field_type('creation_user','readonly',$this->auth_user_id);

}

 

similar for edit:

 

 if ($operation == 'edit' || $operation == 'update' || $operation == 'update_validation') {

 

$crud->field_type('edit_user','readonly',$this->auth_user_id);

}

 

Hope everything is clear. Have a nice day !


kris
  • profile picture
  • Member

Posted 26 May 2017 - 14:18 PM

Thank for your quick answer

 

The problème I have is that when I put

 

$crud->field_type('field_name','readonly');

 

 

I can't update that field in the database.

- Creation date : I have the default value CURRENT_TIMESTAMP

 in the database

 

But when I Update my record I want to update the today's date in the database without having an input field in the form

 

here is my code

    $crud = new grocery_CRUD();
    $crud->set_theme('t17');
    $crud->set_table('gp_user');
    $crud->fields('uscode','usnom','uspass','usdatcrt','usdatupd');

     $crud->display_as('uscode','Code utilisateur');
     $crud->display_as('usnom','Nom');
    

    
     $crud->columns('uscode','usnom');
     $crud->change_field_type('uspass','password');

    //$crud->field_type('usdatcrt','readonly');
    /* if ($operation == 'edit' || $operation == 'update' || $operation == 'update_validation') {
        $crud->field_type('usdatusr','readonly');
    }*/
    $crud->field_type('usdatupd','readonly');
    $crud->field_type('usdatcrt','readonly');
    $crud->callback_before_update(array($this,'beforeupdate'));

    $crud->callback_edit_field('uspass',array($this,'set_password_input_to_empty'));
    $crud->callback_add_field('uspass',array($this,'set_password_input_to_empty'));


    $output = $crud->render();
     $this->_example_output($output);  
    
}


function set_password_input_to_empty() {
return "<input type='password' name='password' value='' />";
}

function beforeupdate($post_array, $primary_key = null)
    {
        if(!empty($post_array['uspass']))
        {
            $post_array['uspass'] = md5($post_array['uspass']);
        }
        else
        {
            unset($post_array['unpass']);
        }
        
    
          $post_array['usdatupd'] = date('Y-m-d');
        return $post_array;
      
    }

The field usdatupd

 is my update date is not updated when I have    

 

$crud->field_type('usdatcrt','readonly');

 

it works well when I comment this line


lblblb
  • profile picture
  • Member

Posted 06 July 2017 - 06:14 AM

Even i have the same query. How do you solve this?

https://www.deardesk.com