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( 'reg' => t('registerinnode'), 'login' => t('Logininnode'), ), '#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' => 14, '#states' => array( 'visible' => array( '.login-reg-select' => array('value' => 'reg'), ), ), ); $form['login'] = array( '#type' => 'fieldset', '#title' => t('Login'), '#weight' => 14, '#states' => array( 'visible' => array( '.login-reg-select' => array('value' => 'login'), ), ), ); $form['register']['form'] = drupal_retrieve_form('user_register_form', $form_state); $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'); } // 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'; $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) { 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; } } /** * 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(); } }