1

In Drupal 7, using the Field module, Field SQL Storage and Field UI I've created several custom user fields. I can display them in PHP like this:

global $user;
$account = user_load($GLOBALS['user']->uid);
if ($items = field_get_items('user', $account, 'field_keys_available')) {
   $keys_remaining = $items[0]['value'];

The above example displays the custom keys_available field, a field we use to determine if the user is entitled to software license keys. I need to decrement field_keys_available in the PHP that issues a license key to a user. Can someone help with the syntax on this? I've discovered fifty ways to generate white screens, but haven't landed on the right syntax.

0

It should be something as simple as

$account = user_load($GLOBALS['user']->uid);
$edit['field_keys_available'][LANGUAGE_NONE][0]['value'] = 'new value';
user_save($account, $edit);

The comments in the user_save() docs have some more details and examples.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.