How to capture form fields to programmatically create new users I briefly worked with Drupal several years ago, and now have come back to it for a single project. For all intents, I'm a total beginner. I need to create a new user from a custom form (html in a block.) I've found some info on how to do the back-end processing (this and this), but can't figure out how to capture the form submission values in my custom module. Can I just use $_POST values? Is that allowed? Or is there some other way I'm supposed to go about it?

My initial module code looks like this:

function create_vector_user_block_info() {
    $blocks['create_vector_user'] = array(
    // The name that will appear in the block list.
    'info' =&gt; t('Create Vector User'),
    // Default setting.
    'cache' =&gt; DRUPAL_CACHE_PER_ROLE,
  );
  return $blocks;
}



function create_vector_user_submit() {
    //This will generate a random password, you could set your own here
  $password = user_password(8);

  //set up the user fields
  $fields = array(
    'name' =&gt; 'user_name',
    'mail' =&gt; 'user_name@example.com',
    'pass' =&gt; $password,
    'status' =&gt; 1,
    'init' =&gt; 'email address',
    'roles' =&gt; array(
      DRUPAL_AUTHENTICATED_RID =&gt; 'authenticated user',
    ),
  );

  //the first parameter is left blank so a new user is created
  $account = user_save('', $fields);

  // If you want to send the welcome email, use the following code

  // Manually set the password so it appears in the e-mail.
  $account-&gt;password = $fields['pass'];

  // Send the e-mail through the user module.
  drupal_mail('user', 'register_no_approval_required', $email, NULL, array('account' =&gt; $account), variable_get('site_mail', 'noreply@example..com'));
}


What I need to do is get the value of a username and email field in my custom block and pass them to the elements in the $fields array.
As AyeshK pointed out there are several examples out there. This should have all the elements you need.

First you must create a form to use in your block with hook_form, create your custom submit handler, and use your form values found in $form_state.