multistep registration from in drupal 7 need to add a user and role Here is my method

test_two_submit($form, &amp;$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' =&gt; $page_one_values['username'], '@email' =&gt; $page_one_values['email'], '@password' =&gt; $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.
// Register this new user.
    $roles = user_roles();
    $userinfo = array(
      'name' =&gt; $name,
      'pass' =&gt; user_password(),
      'init' =&gt; $name,
      'status' =&gt; 1,
      'access' =&gt; REQUEST_TIME,
      // This is where we are different from the default function.
      'roles'        =&gt; array(array_search('campus_student', $roles) =&gt; 1),
      // the field_* values come from custom columns added through
      // thhe admin ui under manage fields for users.
      'field_first_name'   =&gt; array(LANGUAGE_NONE =&gt; array( 0 =&gt; array('value' =&gt; $get_ldap_details['first_name']))),
      'field_last_name'    =&gt; array(LANGUAGE_NONE =&gt; array( 0 =&gt; array('value' =&gt; $get_ldap_details['last_name']))),
      'field_perm_number'  =&gt; array(LANGUAGE_NONE =&gt; array( 0 =&gt; array('value' =&gt; $get_ldap_details['campus_perm_number']))),
      'mail' =&gt; $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.