1

I have Drupal 7 website. Initial requirement was to accept membership from public (anonymous users) without creating a user account. So the plan was to create a content type called ‘membership’ that has the fields Name, email address, mobile number, a unique alphanumeric ID and other fields for personal/professional details.

Now the requirement is changed and need to create a user account for each of this ‘membership’ type of content.

Is there any way to create user accounts from each of existing content of the type ‘Membership’ by fetching email id from the ‘email field’ and password from the ‘unique alphanumeric ID’ field (or some other means)?

1

One solution is using VBO module, create a view with what content type you want ("membership") then perform a run a PHP code operation on them, and put something like this in Php code

$name = $entity->title; //fill it with what field you want
$email = $entity->YOUR_EMAIL_FIELD_MACHINE_NAME['und'][0]['value'];
$pass = $entity->YOUR_PASS_FIELD_MACHINE_NAME['und'][0]['value'];
$new_user = array(
  'name' => $name,
  'pass' => $pass, // note: do not use md5
  'mail' => $email,
  'status' => 1,
  'init' => $email,
  'roles' => array(
    DRUPAL_AUTHENTICATED_RID => 'authenticated user',
  ),
);

// The first parameter is sent blank so a new user is created.
user_save('', $new_user);

and another solution is create your custom Batch operation and try some thing like up snippet.

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.