I have profile 2 installed. I added a new field called "maiden name" to my profile form using the "add existing field" option. I had previously created this field in the default user registration form.

Now I want to delete the field (maiden name) from the user registration form. Please how can I transfer the data/values to the new field in my profile 2 form.

Thank you.


This in untested code so you will need to adjust the paths to get the correct values however it shows the general approach to take:

$uids = db_query("SELECT uid FROM user WHERE status=1")->fetchCol();

foreach($uids as $uid) {
    $account = user_load($uid);
    $profile2 = profile2_load_by_user($account, 'profile_2_type_name_here');
    $profile2['maiden_name']->field_maiden_name[LANGUAGE_NONE][0]['value'] = $account->field_maiden_name[LANGUAGE_NONE][0]['value'];
  • Thank you. Please where do I put this code? – seyi Mar 26 '14 at 16:15
  • In a custom module. – Felix Eve Mar 26 '14 at 16:16

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.