I have taken up the charge of an inline login instead of registration:

http://drupal.org/node/861448
http://drupal.org/node/333582

I can successful login and post if the user validates but have been unsuccessful if validation fails. I get an array flip error that is common to nested arrays.

If someone could look over the code here to see if they see an error we can get this working fairly quickly.

<?php

/**
 * @file
 *
 */


/**
* Implementation of hook_form_alter()
*/
function inline_registration_form_alter(&$form, &$form_state, $form_id) {
  global $user;
  if ($user->uid == 0 && isset($form['#node']) && 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_login', $form_state);
      
    // Remove the user_register submit button in favor of the node submit button
    unset($form['register']['form']['actions']['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') {
    $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,
      '#group'          => 'additional_settings', // put it in the menu settings      
    );
    $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) {
  $form_state['values']['name'] = $form_state['input']['name']; // for some reason the name is empty and a scrypt works incorrectly so copy it from other variable
$form_state['values']['pass'] = $form_state['input']['pass'];
  // Validate using user module's validation routine
  //unset($form_state['uid']);
  user_login_authenticate_validate($form['register']['form'], $form_state);

}

/**
 * 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']); // if not unset the user will be logined

  user_login_submit($form['register']['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_node_insert()
*/
function inline_registration_node_insert($node) {
  if (!empty($node->vid)) {
    //db_query('UPDATE {node_revisions} SET uid = %d WHERE vid = %d', $node->uid, $node->vid);
    $num_updated = db_update('node_revision')
    ->fields(array(
      'uid' => $node->uid,
    ))
    ->condition('vid', $node->vid, '=')
    ->execute();
  }
}

Comments

vvvi’s picture

Status: Active » Postponed (maintainer needs more info)

Can't reproduce. Please try the last vesrsion and describe a result.

thanks

vvvi’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)