How to use hook_node_presave to change field's value Basically, I want to put first name &amp; surname together into $node->field_par_contact_name

But it gives me warning. (See below)


function partnership_node_presave($node) {
  if($node->type == 'partnership') {
    $first_name = $node->field_par_contact_first_name['und'][0]['name'];
    $surname = $node->field_par_contact_surname['und'][0]['name'];

    // https://drupal.org/project/field_hidden
    // Hidden variable
    $node->field_par_contact_name['und'][0]['value'] = $first_name. ' '. $surname;

    // Warning after save: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 173 of .../drupal-7.23/includes/entity.inc
  }
}


Updated, please see image:
For starters, you're probably using the wrong array key for the field value that you're saving; 'name' should be 'value' there.

$node-&gt;field_par_contact_name['und'][0]['value'];


Second, you're actually using Taxonomy Term Reference fields for your "first name" and "surname" fields. One important point about Reference fields is that you can't always assume that the referenced entities have been fully loaded and are available in your object. By default, when the node object is loaded, that field only looks like this:

$node-&gt;field_par_contact_first_name (Array)
  'und' (Array)
    0 (Array)
      'tid' =&gt; 284


Only the 'tid' key is definitely there. 'name' is a property of the referenced term, and isn't usually automatically available. (Subsequent code may actually load the referenced term and make it available within the $node object, but that's just happenstance if so.)

You would have a much easier time of it if your "First Name" and "Surname" fields were text fields instead of references. Then, those values would belong directly to the node itself, rather than to a separate taxonomy term being referenced.

If you're stuck using taxonomy term references, though, then you should make a point in your code to load the referenced term, then get the values you need from the $term->name property itself.