0

Here is my method

test_two_submit($form, &$form_state) {
  $page_one_values = $form_state['page_values'][1];
  drupal_set_message(t('The form has been submitted'));
  $page_one_values = $form_state['page_values'][1];
  drupal_set_message(t('The form has been submitted. name="@username @email", password=@password', array('@username' => $page_one_values['username'], '@email' => $page_one_values['email'], '@password' => $page_one_values['password'])));
}

What i am trying to do is to add a user to my multi-step form.

I guess my two questions are how to add a user and also assign that particular user to a role.

Would it be possible for someone to give a short example.

  • hi Clive thank you for sorting out the code markup but would it be possible to shed some light on creating a user object for my custom registration form. – Alexander Mar 30 '12 at 13:15
1
   // Register this new user.
    $roles = user_roles();
    $userinfo = array(
      'name' => $name,
      'pass' => user_password(),
      'init' => $name,
      'status' => 1,
      'access' => REQUEST_TIME,
      // This is where we are different from the default function.
      'roles'        => array(array_search('campus_student', $roles) => 1),
      // the field_* values come from custom columns added through
      // thhe admin ui under manage fields for users.
      'field_first_name'   => array(LANGUAGE_NONE => array( 0 => array('value' => $get_ldap_details['first_name']))),
      'field_last_name'    => array(LANGUAGE_NONE => array( 0 => array('value' => $get_ldap_details['last_name']))),
      'field_perm_number'  => array(LANGUAGE_NONE => array( 0 => array('value' => $get_ldap_details['campus_perm_number']))),
      'mail' => $get_ldap_details['mail'],
    );
    $account = user_save(drupal_anonymous_user(), $userinfo);

EDIT: You can see how drupal itself typically creates in a user via drupal_external_login_register(). The above example uses some API calls to get all Roles and assigns very clearly X additional roles, it also sets up additional drupal Fields tied to the user entity.

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.