User Tools

Site Tools


drupal

This is an old revision of the document!


Drupal Tips

Some hints, tips and code samples for managing and extending Drupal.

Cron

Directory Structure

Externally Managing Users & Roles

Moving A Site

Updating Custom User fields

I added a custom field to the user object and needed a way to programmatically put data into that field. I found the following code on Drupal:

   $user_fields = user_load($user->uid);    
   $user_fields->field_points['und'][0]['value'] = $points;
   user_save($user_fields);
   

This comes from the following Drupal page:

The actual code that worked retrieved a user, updated the field and then saved it back follows. The field name is 'field_lname.

   $field_data = 'Glembocki';
   $name = 'tomg';
   $user_fields = user_load_by_name($name);
   $user_fields->field_lname['und'][0]['value'] = $field_data;
   user_save($user_fields);
drupal.1512329946.txt.gz · Last modified: 2017/12/03 14:39 by tomgle