More info at sign up + user profile

Events happening in the community are now at Drupal community events on www.drupal.org.
mattmm's picture

Looking for feedback on what others have done to accomplish the following. On sign up, instead of just username, password, and e-mail - how have you tackled gathering more information? I'd like add custom fields - full name, website, etc etc. What's your recipie?

Moreover, the hot topic, building user profiles. The ability to build out a "view" to see a user's infomration and links to all the supplied content of a site (i.e. images, posts, blogs, etc)

Comments

.

michelle's picture

Core profile and bio both let you select fields to put on the registration page. Nodeprofile will only let you add the entire node in one shot. I don't know if content profile has any options for this, yet.

For displaying the profiles, I use panels. This should be an option in D6 fairly soon.

Michelle


See my Drupal articles and tutorials or come check out the Coulee Region

Custom solution

allella's picture

I've used hook_form_alter() to add additional fields to the 'user_register' form. Then, a custom hook_form_validate() to do some custom validation and finally a custom hook_form_submit() which calls drupal_execute(), or node_save(), to submit the extra fields into a profile node.

I share or post D5 or D6 examples if anyone is looking to it with their own custom module.

Great feedback thanks a lot.

mattmm's picture

Great feedback thanks a lot.

Location fields on registration page

paulhudson's picture

The mini module below will add fields from the location module into the signup form. Without this users need to edit their user account to add a location.

<?php
global $user;
if (
arg(0) == "profile" && !arg(1) || arg(0) == "user" && !arg(1)) drupal_goto("profile/$user->name");

#add fields to user form
 
$return = array();
  foreach (
module_implements('locationapi') as $name) {
   
$function = $name .'_locationapi';
   
$result = $function($location, $op, $a3, $a4, $a5);
    if (isset(
$result) && is_array($result)) {
     
$return = array_merge($return, $result);
    }
    else if (isset(
$result)) {
     
$return[] = $result;
    }
  }
#return $return;

function telltrail_user($op, &$edit, &$account, $category = NULL){
#print "<pre style=\"color:#000;font-size:11px;\">"; print_r($user); print "</pre>";
switch ($op){
      case
'register':
         case
'form':
            
$form['contactdets'] = array(
                   
'#title' => t('Contact Address'),
                  
'#type' => 'fieldset'
              
);
            
$form['contactdets']['locations_0_street'] = array(
                   
'#title' => t('Address Line 1'),
                   
'#type' => 'textfield',
                
'#default_value' => isset($account->locations_0_street) ? $account->locations_0_street : false,
                
'#required' => true
              
);
            
$form['contactdets']['locations_0_additional'] = array(
                   
'#title' => t('Address Line 2'),
                   
'#type' => 'textfield',
                
'#default_value' => isset($account->locations_0_additional) ? $account->locations_0_additional : false,
             );
            
$form['contactdets']['locations_0_city'] = array(
                 
'#title' => t('Town/City'),
                
'#type' => 'textfield',
                
'#default_value' => isset($account->locations_0_city) ? $account->locations_0_city : false,
                
'#required' => true
              
);
            
$options = array();
               
$obj = new stdClass();
             if (isset(
$country)){
                 
$countries = array($country => TRUE);
               } else {
                  
$countries = location_configured_countries();
              }
              foreach (
$countries as $cc => $name){
                  
$provinces = location_get_provinces($cc);
                 
sort($provinces);
                  foreach (
$provinces as $province_code => $province_name){
                      
$obj = new stdClass();
                    
#$obj->option = array("$cc-$province_code" => $province_name);
                    
$obj->option = array($province_name => $province_name);
                     
$options[] = $obj;
                 }
              }
             
$form['contactdets']['locations_0_province'] = array(
                 
'#type' => 'select',
                   
'#title' => t('County'),
                   
#'#default_value' => $obj,
                   
'#default_value' => isset($account->locations_0_province) ? $account->locations_0_province : false,
                
'#options' => $options,
                  
'#required' => true
              
);
            
$form['contactdets']['locations_0_postal_code'] = array(
                  
'#title' => t('Post Code'),
                
#'#title' => $a5['country'],
                   
'#type' => 'textfield',
                
'#default_value' => isset($account->locations_0_postal_code) ? strtoupper($account->locations_0_postal_code) : false,
                  
'#required' => true
              
);
             return
$form;
      break;
}
}
?>

Hope this helps someone,

Paul

RealworksMedia.com - Drupal Themes and Development

HudHost
HudHost.com

Custom fields, validation, submit on user_register form

allella's picture

An example of adding fields to the registration form. This example assumes a custom module called "system_custom.module"

  // Implementation of hook_form_alter().
function system_custom_form_alter( &$form, $form_state, $form_id ) {

      // customize the user registration form /user/register
  if ( $form_id == 'user_register' ) {
   

      $form['city'] = array(
           '#title' => t('City'),
          '#type' => 'textfield',
         '#default_value' => '',
         '#required' => FALSE,
         '#attributes' => array( 'tabindex' => 1 ),
       );

        $form['state'] = array(
          '#title' => t('State'),
         '#type' => 'select',
            '#default_value' => '',
         '#required' => FALSE,
         '#attributes' => array( 'tabindex' => 2 ),
           '#options' => array(
              ''    => '',
                'Alabama' => 'Alabama',
             'Alaska' => 'Alaska',
               'Wisconsin' => 'Wisconsin',
             'Wyoming' => 'Wyoming'
          )
      );

        $form['zipcode'] = array(
            '#title' => t('Postal/Zip Code'),
           '#type' => 'textfield',
         '#default_value' => '',
         '#required' => FALSE,
         '#attributes' => array( 'tabindex' => 3 ),
       );

        $form['#redirect'] = check_plain($_REQUEST['q']);   // redirect back to the page they came from

       $form['submit']['#value'] = t( 'Register' );
     $form['submit']['#attributes'] = array( 'tabindex' => 4 );

               // set the form validate to call the regular user_register_validate()
              // (from user.module) and the user_register_validate_custom() (defined in this module)
     $form['#validate'][] = 'user_register_validate_custom';

           // set the form submit to call the regular user_register_submit()
          // (from user.module) and the user_register_submit_custom() (defined in this module)
       $form['#submit'][] = 'user_register_submit_custom';
    }   // end of if, the "user_register" form is being called

} // end of function, system_custom_form_alter()


// A secondary custom form validation function for the user_register form  (i.e the form on  user/register )
function user_register_validate_custom( $form, &$form_state ) {
// some validation could go here

} // end of function "user_register_validate_custom"


// A secondary custom form submit function for the user_register form  (i.e the form on  user/register )
function user_register_submit_custom( $form, &$form_state ) {

    module_load_include('inc', 'node', 'node.pages');
    $nodeTmp = array('type' => 'yourNodeTypeHere'); 

      // set the form values into a temporary array of values, which we'll pass to drupal_execute
   $temp['values']['field_state']['value'] = $form_state['values']['state'];
    $temp['values']['field_city'][0]['value'] = $form_state['values']['city'];
   $temp['values']['field_zipcode'][0]['value'] = $form_state['values']['zipcode'];

    $temp['values']['type'] = 'yourNodeTypeHere';     // the node's CCK type
    $temp['values']['status'] = 0;      // set the node's status to unpublished by default
    $temp['values']['title'] = 'someTitleHere';
  $temp['values']['body'] = '';     // leave the body empty if you want
    $temp['values']['name'] = 'aValidDrupalUserNameHere';
    $temp['values']['op'] = t('Save');  // this seems to be a required value

    $errs = drupal_execute('yourNodeTypeHere_node_form', $temp, (object) $nodeTmp);   // call the function to create the node, node_revisions, and CCK values for the node type

$_SESSION['messages'] = ''; // clear the default message
   drupal_set_message( '<p>Some Custom Message</p>', 'status' );   // set a custom message

}  // end of function user_register_submit_custom

In this example I use the custom submit() function, along with drupal_execute() to programatically create a node upon registration. Of course you could do anything, like fire off an email too. Karen S warns there are some bugs with drupal_execute and CCK field validation, so use drupal_execute with caution. You can apparently do similar things with node_save()

awesome! thanks all for the

mattmm's picture

awesome! thanks all for the feedback.

you can try

kenorb's picture

CCK + Content Profile + Account Profile

Account Profile?

hortitude's picture

Do you mean this module? http://drupal.org/project/account_profile

I'm familiar with Content Profile but have never used Account Profile.

There doesn't look to be much documentation around it. Do you have insight regarding why you would want to use it above and beyond simply using Content_Profile ?

Thanks!

Re: Account Profile

mossy2100's picture

It sounds a lot like One Page Profile, except that it works with Content Profile instead of the default Profile module. However, there are no published releases for Account Profile.

I am just using Content Profile.

Account Profile

kenorb's picture

it's new one, onepageprofile doesn't work with Content Profile, and Account Profile has been created to make it very simple.

cool

mossy2100's picture

That's cool, kenorb - will give it a try!

Social Networking Sites

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week