function inline_registration_form_alter in Inline Registration 5
Same name and namespace in other branches
- 6 inline_registration.module \inline_registration_form_alter()
- 7 inline_registration.module \inline_registration_form_alter()
Implementation of hook_form_alter().
File
- ./
inline_registration.module, line 11
Code
function inline_registration_form_alter($form_id, &$form) {
if ($form['type']['#value'] . '_node_form' == $form_id && variable_get('inline_registration_' . $form['#node']->type, 0) && arg(1) == 'add') {
// This is a node/add form
global $user;
if ($user->uid == 0) {
// User is not logged in
// Add the user registration form to the node/add/page
$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', NULL, 'destination=' . $_GET['q']),
)),
'#weight' => variable_get('inline_registration_weight_' . $form['#node']->type, 0),
);
$user_register_form = user_register();
foreach (module_implements('form_alter') as $module) {
$function = $module . '_form_alter';
$function('user_register', $user_register_form);
}
$form['register']['form'] = $user_register_form;
// Remove the user_register submit button in favor of the node submit button
$form['register']['form']['submit'] = NULL;
// 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'] = array();
$form['#submit']['inline_registration_submit'] = array();
// 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."),
);
}
}