I want to add additional informations to a user on registration. I have added the fields accountID and clanID to the user . On registration i load these information according to his entered name from another webpage and i want to have these fields added to the user.

My question is, how can i add these additional values to the fields programmatically?


3 Answers 3


How about using the Profile 2 module for this? Exceerpt from its project page:

Designed to be the successor of the core profile module, which is deprecated for Drupal 7. In contrast to the deprecated module this module provides a new, fieldable 'profile' entity ... leverage the power of fields!

Refer to this video for an introduction to Profile 2 also.

Maybe you also want to consider something like the answer to How to display a profile form using profile2 module ?

  • I know the Profile 2 module. And i have already the additional fields. All i want is, that i can fill these fields during registration programmatically. Commented May 24, 2015 at 17:13

I guess you could use the Prepopulate module for this.

The Prepopulate module allows fields in most forms to be pre-populated from the $_REQUEST variable.

For example, the following URL,

http://www.example.com/node/add/blog?edit[title]=this is the title

will automatically fill the Title field on a new blog post with the words "this is the title". Any field can be prepopulated this way, including taxonomy and CCK fields. You can prepopulate more than one field at a time as well. Prepopulate is excellent for creating bookmarklets. For examples on usage for all of these cases, please read the USAGE.txt file that comes with the module or you can read the online handbook page.

That should be able to get the information in the field assuming you can add those into the link that is clicked to get to the registration page.


Thank you for the hints. I have solved it with the user_presave_hook:

function mymodule_user_presave(&$edit, $account, $category) {
$url = variable_get('url');
$account_id = $edit['field_accountid']['und'][0]['value'];

try {
    $api_response = json_decode(file_get_contents($url), true);     

    $edit['field_accountid']['und'][0]['value'] = $account_id;
    $edit['field_global_rating']['und'][0]['value'] = $api_response['data'][$account_id]['global_rating'];
} catch (Exception $e) {
    watchdog('mymodule', 'Could not load account_id from url', NULL, WATCHDOG_WARNING, $link = NULL);


But i don't know if this is a good solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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