I wish to be able to create users using data from an external database.

I have managed to do the basics with user_save() but I can't work out how to include a value for an added field in the creation process. In this case the extra field is an employee number whch is used as a foroegn key back to the extrernal database.

In it's simpllest form I have:

$new_user = array(name=>joebloggs,
                          password=>easy,
                          mail=>joe@somewhere.com,
                          status=>1,
                          init=>joe@somewhere.com,
                          field_emp_no=>WMS0001);

$new_user= user_save(null,$new_user);

The creates the user but does not populate the added field. The object returned does have a field_emp_no attribute with a value of 'WMS0001' but this is not the same.

Thanks

Comments

crislewis’s picture

Anyone know if this is possible?

aaustin’s picture

I have a user with four additional fields:
first, last, job title and organization

The following code has seemed to work for me:

$edit = array();
$edit['name'] = 'username';
$edit['pass'] = 'password';
$edit['mail'] = 'email@email.co.uk';
$edit['status'] = 1;
$edit['access'] = 0;
$edit['login'] = 0;
$edit['data'] = FALSE;
$edit['roles'] = array(2 => 'authenticated user', 3 => 'another role');
$edit['field_first']['und'][0]['value'] = 'First name';
$edit['field_last']['und'][0]['value'] = 'Last name';
$edit['field_job_title']['und'][0]['value'] = 'Some Job Title';
$edit['field_organization']['und'][0]['value'] = 'Some Company';
user_save(null, $edit);