Hello,

Is this setup currently possible?
1) Anonymous user registers and is *required* to enter field_firstname and field_lastname info.
2) User logs in and is given choice to create a profile (content profile), therefore the content profile is not created yet. IF user chooses to create a profile the first name and last name fields are already populated (from registration) and the rest of the fields for the profile are also *required* to complete the profile creation.

I have tried to set this up but all the fields i set to *required* show on the registration page at this time.

I hope my description above is clear. I would really appreciate any pointers!

Thank you in advance

Comments

eddy147’s picture

You can also achieve this by doing the following.

Suppose you have a role 'actor'.

if you want to register a user as an actor let them go to /user/register/actor.

In your module, create the hook user (see http://api.drupal.org/api/function/hook_user/6).

When a user signs up, he will have to fill his full name, and when a user has signed up as 'actor', you can make him fill up a form before he can continue:

/**
 * Implementation of hook_user().
 */
function YOURMODULE_user($op, &$edit, &$user, $category = NULL) {
    switch($op) {
        case 'register':
            $fields['firstname'] = array(
                '#title' => t('Firstname'),
                '#type' => 'textfield',
                '#required' => TRUE,
                '#weight' => -20,
            );
            $fields['lastname'] = array(
                '#title' => t('Lastname'),
                '#type' => 'textfield',
                '#required' => TRUE,
                '#weight' => -18,
            );
            if (arg(2) == 'actor') {
                $fields['agent'] = array(
                    '#title' => t('Agent'),
                    '#type' => 'textfield',
                    '#required' => TRUE,
                    '#weight' => -9,
                );
                $fields['address'] = array(
                    '#title' => t('Address'),
                    '#type' => 'textfield',
                    '#required' => TRUE,
                    '#weight' => -7,
                    '#description' => t('Address'),
                );
                $fields['city'] = array(
                    '#title' => t('City'),
                    '#type' => 'textfield',
                    '#required' => TRUE,
                    '#weight' => -5,
                );
                $fields['phone'] = array(
                    '#title' => t('Telephone'),
                    '#type' => 'textfield',
                    '#required' => FALSE,
                    '#weight' => -4,
                );
            }
            return $fields;
            break;
        case 'insert':
            add_name($user, $edit);
            if (arg(2) == 'actor') {
                add_actor_data($user, $edit);
            break;
        case 'login':
            if (in_array('actor', $user->roles)) {
                $_REQUEST['destination'] = 'movies/'.$user->username;
            }
            break;

    }
}

/**
 * Add full name for this user
 */
function add_name($user, $edit) {
 ...
}

/**
 * Add data specific for actor role
 */
function add_actor_data($user, $edit) {
 ...
}
Bilmar’s picture

eddy147 - thanks for the great info!

I have a few questions (most likely as I am still new to Drupal and programming).
1) should I be using autoassignrole module to set the path to /user/register/actor ?
2) should the checkbox to have content profile fields at registration be checked?
if no, does the above custom module put the data into the same table as the content profile?
3) should the fields in the content profile be set to required or not required? (i would like to eventually have the fields required when user registers and going to Create Profile link.
3) sorry, i am not clear what goes into this section:
/**
* Add full name for this user
*/
function add_name($user, $edit) {
...
}

/**
* Add data specific for actor role
*/
function add_actor_data($user, $edit) {
...
}

I apologize for the many questions but would really appreciate the additional support!

I feel this will help me really understand how things work and lead to better understanding other areas of drupal and programming.

Thank you!

eddy147’s picture

1) No, you can just use user/register/whatveryouwant

2) No, because you do it explicitely. You have to check it as a content profile in the content type, otherwise a user can make more than 1

3) If you want them to fill a field, it should be required, that's up to you.

4) the function add_name($data) you can do something like this:

function add_name($data) {
    $node = new stdClass();
    $node->title = t('Full name of user');
    $node->body = "";
    $node->type = 'personalia';
    $node->created = time();
    $node->changed = $node->created;
    $node->status = 1;
    $node->promote = 0;
    $node->sticky = 0;
    $node->format = 0;
    $node->uid = $data['uid'];
    $node->language = 'nl';
    $node->field_firstname[0]['value'] = $data['firstname'];
    $node->field_surname[0]['value'] = $data['lastname'];
    node_save($node);
}

What you also need first is a content type 'personalia' with fields firstname and surname.
Make sure content profile is checked: so this content type is a content profile node type.
Then u can use this function.
What this does is it makes an object node and fills the object with the data from the form.
Note that you only need to pass $edit parameter, the uid is in $edit['uid']. So in my original post the call would be
add_name($edit);

The other function is similar.

Bilmar’s picture

Hi eddy147,

I was wondering with the code above, how to make sure the data is being stored in the actor's content profile that I create beforehand.
For example, if there is also a teacher's content profile and registration at user/register/teacher.

The function add_name($user, $edit) and the function add_actor_data($user, $edit) is both storing the user's info from the registration page into the content profile I sent up beforehand right?

Where could I get the complete info/code to use for the content profile I create beforehand to use in the functions to add the user's information?

I think if I can understand the above I will better understand what is happening.
I'm having trouble grasping the relation between the content profile and all the fields I created beforehand and to stuff I am putting into the template of the registration.

Thanks so much!