Setting a new users profile fields based on a form Users on my site all have a &quot;home region&quot; field. This profile field is saved for each user and used to customise various site features, so that the user gets shown local content.
These regions aren't states or cities - they're more like electorate / local council boundaries (I'm not really sure what the US analogy would be). Most users are going to be uncertain about which region they actually want to save to their user profile.
I have a form which allows users to either (A) explicitly select their region from a select dropdown or (B) enter their postcode, submit the form, and get back their region. This form works fine.
I want users to be able to pick a region at registration time using this form, and have that region saved to their profile. Ideally I'd like to integrate the &quot;select region&quot; form with the user_register form, so that they can submit the form, get told &quot;you are part of X region&quot; and then click &quot;register&quot; and create a new user account with that region.
What I'm doing is using hook_user() to insert my form elements, perform my extra validation and then try to save the region data to the user on submit.
EDIT: the below is roughly how I solved this
function mymodule_user($op, &amp;$edit, &amp;$account, $category = NULL) {
  /* add &quot;select your region&quot; functionality to the user edit form */
  $category = 'Regional information';
  switch ($op) {
    case 'register':
    case 'form':
        /* &quot;register&quot;: The user account registration form is about to be displayed. The module should present the form elements it wishes to inject into the form. */
        /* &quot;form&quot;: The user account edit form is about to be displayed. The module should present the form elements it wishes to inject into the form. */
        $form = array();
        $form['Regional information']['region'] = _region_select('', _region_select_options());
        $form['Regional information']['postcode'] = _postcode();
        return $form;
        break;
    case 'validate':
        /* &quot;validate&quot;: The user account is about to be modified. The module should validate its custom additions to the user object, registering errors as necessary. */
        $region = $account['region'];
        $postcode = $account['postcode'];
        // form_set_error() if I need to
        break;
    case 'insert':
    case 'update':
        /* submit happens *before* the user account is saved - we want insert or update
           &quot;insert&quot;: The user account is being added.  
           &quot;update&quot;: The user account is being changed.
           The module should save its custom additions to the user object into the database and set the saved fields to NULL in $edit. */
        $region_code = $edit['region'];
        $postcode = $edit['postcode'];
        if (!$region_code &amp;&amp; $postcode) { // pull the region from the postcode
            ...
        }
        if ($region_code) {
            $region_term = taxonomy_get_term($region_code);
            $region_name = $region_term-&gt;name;
            /* the profile module wants the name of the region, not the id */
            $profile_edit = array( 'profile_region' =&gt; $region_name );
            profile_save_profile($profile_edit, $account, $category);
        }
        break;
  }
}
Do you think you could just make the select dropdown and postcode input box parts of the user_form? Looks like you've got the functionality working already, so it would be a matter of a simple module implementing the following hook:


hook_user(register) to alter the registration form and add your custom fields. You'll want to use a profile or profile_taxonomy functionality to insert the form element
hook_user(validate) to validate the user input (incorrect postcode etc.)
hook_user(submit) to convert the postcode to region and to save that information in the user profile