Is it possible to have the login form on the same page also? So basically the user has a option to either login or register and complete the content creation.

Comments

UNarmed’s picture

Users might already have an account and it would be silly sending them to another page when they could login and complete the node fields on the same page.

castelar’s picture

+1 subscribed

UNarmed’s picture

Hmm so i ended up just having the login block in my side bar ... not ideal but suppose the result is sort of the same.

Lbob’s picture

subscribing
http://drupal.org/project/inline_ajax_login should have done the trick, but it's too buggy and doesn't seem supported now...

geek-merlin’s picture

netentropy’s picture

I was able to get this feature working this way


<?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/register', 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_name_validate($form['register']['form'], $form_state);
  user_login_authenticate_validate($form['register']['form'], $form_state);
  user_login_final_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();
  }
}

netentropy’s picture

Assigned: Unassigned » netentropy
Status: Active » Fixed
itserich’s picture

The Fancy Login module makes it easy to create a link with a popup login.

Any link to /user/login pops up with a login box without leaving the page.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

n20’s picture

hi netentropy, when you say you got that working are you talking about the link to the login page or do you actually have the login form on the node creation page? i copy and pasted your code to the module but nothing really changed - may already implementet?

cheers, N20

arbel’s picture

StatusFileSize
new7.57 KB

Here's a patch that adds a radio button, to select login or registration.

Idan

matiaslezin’s picture

I did the same as #3, but my login block is not working. I cannot login. The wierd thing is that it works on the other pages. Any ideas why this could be?

gillisig’s picture

arbel, I am guessing that your patch is for drupal 7? not 6?

arbel’s picture

Yup.

maked1sky’s picture

StatusFileSize
new6.5 KB

After patching module with 861448_login_plus_reg.patch appears 500 ERROR
Tell me what the problem is?
Maybe I made a mistake in the code
file attached

maked1sky’s picture

Anyone uses Login form on same page in Inline Registration?

proweb.ua’s picture

Issue summary: View changes

#13

before

/**
 * Implements hook_node_insert().
 */
function inline_registration_node_insert($node) {

add

}

works for me

szt’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Assigned: netentropy » Unassigned
Category: Support request » Feature request
Status: Closed (fixed) » Needs review
szt’s picture

Status: Needs review » Needs work

Needs reroll for the latest dev (if possible).

Itrynator’s picture

Was this module ever working? User registers or logs in but content is not being created..

mtoscano’s picture

Status: Needs work » Needs review

The patch at #6 does not apply against latest version, but the logic still works.
The patched module looks like

<?php

/**
 * @file
 * Allow anonymous users to register via the node/add page.
 */

/**
 * Implements 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['login_or_reg'] = array(
      '#type' => 'radios',
      '#title' => t('Login Or Register'),
      '#options' => array(
        'login' => t('Login'),
        'reg' => t('Register'),
      ),
      '#default_value' => 'reg',
      '#attributes' => array('class' => array('login-reg-select')),
      '#weight' => variable_get('inline_registration_weight_' . $form['#node']->type, 0),
    );

    $form['register'] = array(
      '#type' => 'fieldset',
      '#title' => t('Register as a New User'),
      '#weight' => variable_get('inline_registration_weight_' . $form['#node']->type, 0),
      '#states' => array(
        'visible' => array(
          '.login-reg-select' => array('value' => 'reg'),
        ),
      ),
    );

    $form['login'] = array(
      '#type' => 'fieldset',
      '#title' => t('Login'),
      '#weight' => variable_get('inline_registration_weight_' . $form['#node']->type, 0),
      '#states' => array(
        'visible' => array(
          '.login-reg-select' => array('value' => 'login'),
        ),
      ),
    );

    // Let other modules to alter this inline user_register form
    // with using hook_form_alter() or hook_form_FORM_ID_alter().
    $reg_form_id = 'user_register_form';
    $reg_form = drupal_retrieve_form($reg_form_id, $form_state);
    $reg_form['#id'] = $reg_form_id;
    $hooks = array('form', 'form_' . $reg_form_id);
    drupal_alter($hooks, $reg_form, $form_state, $reg_form_id);
    $form['register']['form'] = $reg_form;

    $form['login']['form'] = drupal_retrieve_form('user_login', $form_state);

    // If the email_registration module is installed, the registration form
    // needs a bit more processing.
    if (module_exists('email_registration')) {
      // Calling drupal_prepare_form recursively calls all form_alter hooks and
      // causes warnings, so it cannot be used here. Instead, call the named
      // hook_form_FORM_ID_alter function from email_registration directly.
      email_registration_form_user_register_form_alter($form['register']['form'], $form_state, 'user_register_form');
    }

    // If the logintoboggan module is installed, the registration form
    // needs a bit more processing.
    if (module_exists('logintoboggan')) {
      // Calling drupal_prepare_form recursively calls all form_alter hooks and
      // causes warnings, so it cannot be used here. Instead, call the named
      // hook_form_FORM_ID_alter function from email_registration directly.
      logintoboggan_form_user_register_form_alter($form['register']['form'], $form_state);
    }

    // If the registration_toboggan module is installed, the registration form
    // needs a bit more processing.
    if (module_exists('registration_toboggan')) {
      // Calling drupal_prepare_form recursively calls all form_alter hooks and
      // causes warnings, so it cannot be used here. Instead, call the named
      // hook_form_FORM_ID_alter function from email_registration directly.
      registration_toboggan_form_user_register_form_alter($form['register']['form'], $form_state, 'user_register_form');
    }

    // Remove the user_register submit button in favor
    // of the node submit button.
    unset($form['register']['form']['actions']['submit']);
    unset($form['login']['form']['actions']['submit']);
    unset($form['login']['form']['#validate']);
    unset($form['register']['form']['#validate']);
    $form['login']['form']['login_name'] = $form['login']['form']['name'];
    $form['login']['form']['login_pass'] = $form['login']['form']['pass'];
    unset($form['login']['form']['name']);
    unset($form['login']['form']['pass']);
    //remove requierd from fileds
    unset( $form['login']['form']['login_name']['#required']);
    unset( $form['login']['form']['login_pass']['#required']);
    foreach ($form['register']['form']['account'] as $key => $feild) {
      if (is_array($form['register']['form']['account'][$key]) && isset($form['register']['form']['account'][$key]['#required'])) {
        unset($form['register']['form']['account'][$key]['#required']);
      }
    }


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

    // Add our own validation and submit function to the node_form
    $form['#validate'][] = 'inline_registration_validate';
    if (is_array($form['#submit'])) {
      // And ensure our submit function is called first
      // (so the node is authored by the newly created user).
      array_unshift($form['#submit'], 'inline_registration_submit');
    }
    else {
      $form['#submit'] = array('inline_registration_submit');
    }

  }

  if ($form_id == 'node_type_form') {
    $form['inline_registration'] = array(
      '#type'           => 'fieldset',
      '#title'          => t('Inline registration'),
      '#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,
      // Put it in the menu settings.
      '#group'          => 'additional_settings',
    );
    $form['inline_registration']['inline_registration'] = array(
      '#type'           => 'checkbox',
      '#title'          => t('Inline registration'),
      '#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) {
  // For some reason the name is empty and a scrypt works
  // incorrectly so copy it from other variable.
if ($form_state['values']['login_or_reg'] == 'reg') {
    $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

    unset($form_state['uid']);
    if (module_exists('logintoboggan')) {
      logintoboggan_user_register_validate($form['register']['form'], $form_state);
    }
    else {
      // Validate using user module's validation routine
      user_account_form_validate($form['register']['form'], $form_state);
    }
  }
  else {
    $form_state['values']['name'] = $form_state['input']['login_name'];
    $form_state['values']['pass'] = $form_state['input']['login_pass'];
    $form_state['input']['name'] = $form_state['input']['login_name'];
    $form_state['input']['pass'] = $form_state['input']['login_pass'];
    unset($form['register']);
    $form_state['values']['pass'] = $form_state['input']['login_pass'];
    $form['login']['form']['name'] = $form['login']['form']['login_name'];
    $form['login']['form']['pass'] = $form['login']['form']['login_pass'];
    unset($form['login']['form']['login_name']);
    unset($form['login']['form']['login_pass']);
    //we need to ignore registration password field, password do not match error
    $errors = form_get_errors();
    if (!empty($errors)) {
      foreach ($errors as $key => $error) {
        if ($key == 'pass') {
          form_clear_error();
          drupal_get_messages('error');
        }
      }
    }
    user_login_name_validate($form['login']['form'], $form_state);
    user_login_authenticate_validate($form['login']['form'], $form_state);
    user_login_final_validate($form['login']['form'], $form_state);
   }

}

/**
 * Submit routine for inline registration form.
 */
function inline_registration_submit($form, &$form_state) {
  if ($form_state['values']['login_or_reg'] == 'reg') {
    if (variable_get('user_email_verification', TRUE)) {
      $status_save = 1;
    }
    else {
      $status_save = $form_state['values']['status'];
    }

    unset($form_state['values']['uid']);
  //  unset($form_state['values']['status']); // if not unset the user will be logined

    if (module_exists('logintoboggan')) {
      logintoboggan_user_register_submit($form['register']['form'], $form_state);
    }
    else {
      user_register_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;
  }
  else {
    $status_save = $form_state['values']['status'];
    unset($form_state['values']['status']); // if not unset the user will be logined
    user_login_submit($form['login']['form'], $form_state);
    $form_state['values']['status'] = $status_save;
  }
}

/**
 * Implements hook_node_insert().
 */
function inline_registration_node_insert($node) {
  if (!empty($node->vid)) {
    $num_updated = db_update('node_revision')
    ->fields(array(
      'uid' => $node->uid,
    ))
    ->condition('vid', $node->vid, '=')
    ->execute();
  }
}

Anyway, from a user interface point of view the radio option is probably not the best solution, and in case the email already exist the user should be presented directly with the login form. At the moment receives a message at the top of the page about resetting the password that open a new page.

geek-merlin’s picture

Status: Needs review » Needs work

@mato #21: thanks for your contribution, but this is not a patch (neither is #6) and for several reasons will not be useful.
If you want to help bring this forward, read this and upload your patch.
Making a Drupal patch with Git | Drupal.org