Question

i have a cck custom type that is created by people and the fields are filled. Then someone else edit those nodes and adds more data. I want to save the username of the user editing the content into an hidden field.

i know i can get the user with this:

global $user;
$a = $user->name;
return array(
  0 => array('value' => $a)
);

and i have put this as default code for the hidden field, but the field now is filled with the creator of the node, and then is not replaced with the editor. How can i solve my issue?

Was it helpful?

Solution

i do research on your problem, here is a solution enjoy!!!

Create a custom module and use the following code.

//Implementation of hook_nodeapi()
function hook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch($op) {
    case 'presave':
        if($node->type == "Your content type name")
        {
          global $user;
          //In my case
          //$node->field_username[0]['value'] = $user->name;
          //In your case it will be like
          $node->hidden_field_name[0]['value'] = $user->name;
        }
      break;
  }    
}

OTHER TIPS

When you test editing the node yourself, does the field contain your own username or the original author?

An alternative solution is to form_alter the specific node edit form and on node_save, fill in the hidden field with the user name.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top