Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bartik_copy_user_login($form, &$form_state) {
- global $user;
- // If we are already logged on, go to the user page instead.
- if ($user->uid) {
- drupal_goto('user/' . $user->uid);
- }
- // Display login form:
- $form['name'] = array('#type' => 'textfield',
- '#title' => t('Username'),
- '#size' => 60,
- '#maxlength' => USERNAME_MAX_LENGTH,
- '#required' => TRUE,
- );
- $form['name']['#description'] = t('Enter your @s username.', array('@s' => variable_get('site_name', 'Drupal')));
- $form['pass'] = array('#type' => 'password',
- '#title' => t('Password'),
- '#description' => t('Enter that accompanies your username.'),
- '#required' => TRUE,
- );
- $form['address'] = array('#type' => 'textfield',
- '#title' => t('Your address'),
- '#size' => 60,
- '#maxlength' => 125,
- '#required' => TRUE,
- );
- $form['#validate'] = user_login_default_validators();
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Log in'));
- return $form;
- }
- function mymodule_form_user_register_form_alter(&$form, &$form_state, $form_id) {
- $form['address'] = array('#type' => 'textfield',
- '#title' => t('Your address'),
- '#size' => 60,
- '#maxlength' => 125,
- '#required' => TRUE,
- );
- }
- function MYMODULE_enable() {
- // Check if our field is not already created.
- if (!field_info_field('field_myField')) {
- $field = array(
- 'field_name' => 'field_myField',
- 'type' => 'text',
- );
- field_create_field($field);
- // Create the instance on the bundle.
- $instance = array(
- 'field_name' => 'field_myField',
- 'entity_type' => 'user',
- 'label' => 'My Field Name',
- 'bundle' => 'user',
- // If you don't set the "required" property then the field wont be required by default.
- 'required' => TRUE,
- 'settings' => array(
- // Here you inform either or not you want this field showing up on the registration form.
- 'user_register_form' => 1,
- ),
- 'widget' => array(
- 'type' => 'textfield',
- ),
- );
- field_create_instance($instance);
- }
- }
- /**
- * Implements hook_form_FORM_ID_alter().
- */
- function foo_form_user_register_form_alter(&$form, &$form_state, $form_id) {
- $form['account']['mail_confirm'] = array(
- '#type' => 'textfield',
- '#title' => t('Confirm e-mail address'),
- '#maxlength' => EMAIL_MAX_LENGTH,
- '#description' => t('Please confirm your e-mail address.'),
- '#required' => TRUE,
- );
- $form['#validate'][] = 'foo_user_register_form_validate';
- }
- /**
- * Implements validation callback.
- */
- function foo_user_register_form_validate(&$form, &$form_state) {
- if ($form_state['values']['mail'] != $form_state['values']['mail_confirm']) {
- form_set_error('mail_confirm', 'The email addresses must match.');
- }
- }
Add Comment
Please, Sign In to add comment