Hi,

I would like to use Inline Registration with the Content Profile and Content Profile User Registration profile. The later adds fields from specified content types to the user registration form and creates the corresponding profile nodes on user registration. Obviously field addition is done through hook_form_alter.

It seems that hook_form_alter implementations are not invoked when adding the user registration form into the node creation one.

I tried to add a simple call to drupal_prepare_form in inline_registration_form_alter like this

function inline_registration_form_alter(&$form, $form_state, $form_id) {
  global $user;
  if ($user->uid == 0 && variable_get('inline_registration_'. $form['#node']->type, 0)) { 

    //...
      
    $form['register']['form'] = drupal_retrieve_form('user_register', $form_state);
    
    drupal_prepare_form('user_register', $form['register']['form'], $form_state);
    
    // Remove the user_register submit button in favor of the node submit button
    unset($form['register']['form']['submit']);

    // Rename the user field to remind the user that this is the registration form and not a login field
    $form['register']['form']['name']['#title'] = t('Choose a Username');

    //...
    
  }
  //...
}

Of course it doesn't work. The form is now completed with the fields from content_profile_registration_form_alter hook. But form submission does not behave correctly and instead returns to the page with all field empty and no error message.

I would try to dig this issue later. In the meantime, any help or advice would be appreciated.

Comments

betz’s picture

Yeah, i'm looking for exactly the same.
Did you had any luck with this?

mlncn’s picture

Changing the weight of the module (such that inline_registration comes after content_profile) is probably the most common, simple approach to this sort of problem.

betz’s picture

Tried this, but this doesn't work neither.

Changed the weight to -20 once, cleared caches, nothing changes.
Also tried to change weigt to 20 and cleared my caches.

@benjamin, are you sure this will work then, is it working with you somewhere?

mlncn’s picture

@betz - um, are you using mongolito404's code?

betz’s picture

Aahh, LOL

No, will try it now...

thanks ;)

betz’s picture

woohooo, it works!

thanks a lot

betz’s picture

Status: Active » Reviewed & tested by the community

Can this be commited?

Anonymous’s picture

Hello,
I have the same problem and do all of this thread but nothing works.

This is my inline-registration.modul:

// $Id: inline_registration.module,v 1.1.4.6 2010/07/05 07:53:52 livido Exp $

/**
 * @file
 *
 */


/**
 * Implementation of hook_form_alter().
 */
function inline_registration_form_alter(&$form, $form_state, $form_id) {
  global $user;
  if ($user->uid == 0 && variable_get('inline_registration_'. $form['#node']->type, 0)) { 
      
    $form['register'] = array(
      '#type' => 'fieldset',
      '#title' => t('Login or Register as a New User'),
      '#description' => t('You are not currently logged in. In order to post this item please !login or provide the following details to register.', array('!login' => l(t('login now'), 'user/login', array('query' => drupal_get_destination())))),
      '#weight' => variable_get('inline_registration_weight_'. $form['#node']->type, 0),
    );
      
    $form['register']['form'] = drupal_retrieve_form('user_register', $form_state);drupal_prepare_form('user_register', $form['register']['form'], $form_state);
      
    // Remove the user_register submit button in favor of the node submit button
    unset($form['register']['form']['submit']);

    // Rename the user field to remind the user that this is the registration form and not a login field
    $form['register']['form']['name']['#title'] = t('Choose a Username');

    // Add our own validation and submit function to the node_form
    $form['#validate'][] = 'inline_registration_validate';
    $form['#submit'][] = 'inline_registration_submit';

    // And ensure our submit function is called first (so the node is authored by the newly created user)
    $form['#submit'] = array_reverse($form['#submit']);
    
  }
    
  if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
    $form['inline_registration'] = array(
      '#type'           => 'fieldset',
      '#title'          => t('Registration inline'),
      '#description'    => t('Setting for publishing this content from anonymous user, and automatically create account for this.'),
      '#weight'         => 20,
      '#collapsible'    => TRUE,
      '#collapsed'      => variable_get('inline_registration_'. $form['#node_type']->type, 0) ? FALSE : TRUE,
    );
    $form['inline_registration']['inline_registration'] = array(
      '#type'           => 'checkbox',
      '#title'          => t('Registration inline'),
      '#default_value'  => variable_get('inline_registration_'. $form['#node_type']->type, 0),
      '#description'    => t('Enable user creation from this content.'),
    );
    $form['inline_registration']['inline_registration_weight'] = array(
      '#type'           => 'weight',
      '#title'          => t('Weight of field'),
      '#default_value'  => variable_get('inline_registration_weight_'. $form['#node_type']->type, -10),
      '#description'    => t("Select weight for this field into content creation form."),
      '#delta' => 50,
    );
  }
  
}

/**
 * Validation routine for inline registration form.
 */
function inline_registration_validate($form, &$form_state) {
  // Validate using user module's validation routine
  unset($form_state['uid']);
  user_module_invoke('validate', $form_state['values'], $form_state['values'], 'account');
}

/**
 * Submit routine for inline registration form.
 */
function inline_registration_submit($form, &$form_state) {
  $status_save = $form_state['values']['status'];
  unset($form_state['values']['uid']);
  unset($form_state['values']['status']);
  
  user_register_submit($form, $form_state);

  $form_state['values']['name'] = $form_state['user']->name;
  $form_state['values']['uid'] = $form_state['user']->uid;
  $form_state['values']['status'] = $status_save;
}

/**
 * Implementation of hook_nodeapi().
 */
function inline_registration_nodeapi(&$node, $op, $teaser, $page) {
  // Save user uid to node_revisions table when require e-mail verification.
  global $user;
  if($user->uid != 0) return;
  switch ($op) {
    case 'insert':
      if (!empty($node->vid)) {
        db_query('UPDATE {node_revisions} SET uid = %d WHERE vid = %d', $node->uid, $node->vid);
      }
      break;
  }
  return; 
}

I changed the weigth to 20 and to -20
The weight of Content Profile User Registration is 1

Please, help me.

Kind regards
Tom

alongir’s picture

Hi.

Using drupal_prepare_form breaks the rest of the node/add/ form. The inline registration works perfect. The content profile fields are added. However the rest of the form breaks (only CCK list fields actually).

Any ideas?

lucascaro’s picture

Hi all, just wanted to add that this looked like working, but it breaks cck text fields (option widgets).

lucascaro’s picture

Status: Reviewed & tested by the community » Needs work

Sorry, I'm just marking it as needs work to reflect the cck isues alongir and I are having.

elaman’s picture

Status: Needs work » Closed (outdated)

Issue is very old. Closing it.