Guest User

Untitled

a guest
Jul 8th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. function bartik_copy_user_login($form, &$form_state) {
  2. global $user;
  3.  
  4. // If we are already logged on, go to the user page instead.
  5. if ($user->uid) {
  6. drupal_goto('user/' . $user->uid);
  7. }
  8.  
  9. // Display login form:
  10. $form['name'] = array('#type' => 'textfield',
  11. '#title' => t('Username'),
  12. '#size' => 60,
  13. '#maxlength' => USERNAME_MAX_LENGTH,
  14. '#required' => TRUE,
  15. );
  16.  
  17. $form['name']['#description'] = t('Enter your @s username.', array('@s' => variable_get('site_name', 'Drupal')));
  18. $form['pass'] = array('#type' => 'password',
  19. '#title' => t('Password'),
  20. '#description' => t('Enter that accompanies your username.'),
  21. '#required' => TRUE,
  22. );
  23. $form['address'] = array('#type' => 'textfield',
  24. '#title' => t('Your address'),
  25. '#size' => 60,
  26. '#maxlength' => 125,
  27. '#required' => TRUE,
  28. );
  29.  
  30. $form['#validate'] = user_login_default_validators();
  31. $form['actions'] = array('#type' => 'actions');
  32. $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Log in'));
  33.  
  34. return $form;
  35. }
  36.  
  37. function mymodule_form_user_register_form_alter(&$form, &$form_state, $form_id) {
  38. $form['address'] = array('#type' => 'textfield',
  39. '#title' => t('Your address'),
  40. '#size' => 60,
  41. '#maxlength' => 125,
  42. '#required' => TRUE,
  43. );
  44. }
  45.  
  46. function MYMODULE_enable() {
  47. // Check if our field is not already created.
  48. if (!field_info_field('field_myField')) {
  49. $field = array(
  50. 'field_name' => 'field_myField',
  51. 'type' => 'text',
  52. );
  53.  
  54. field_create_field($field);
  55.  
  56. // Create the instance on the bundle.
  57. $instance = array(
  58. 'field_name' => 'field_myField',
  59. 'entity_type' => 'user',
  60. 'label' => 'My Field Name',
  61. 'bundle' => 'user',
  62. // If you don't set the "required" property then the field wont be required by default.
  63. 'required' => TRUE,
  64. 'settings' => array(
  65. // Here you inform either or not you want this field showing up on the registration form.
  66. 'user_register_form' => 1,
  67. ),
  68. 'widget' => array(
  69. 'type' => 'textfield',
  70. ),
  71. );
  72.  
  73. field_create_instance($instance);
  74. }
  75. }
  76.  
  77. /**
  78. * Implements hook_form_FORM_ID_alter().
  79. */
  80. function foo_form_user_register_form_alter(&$form, &$form_state, $form_id) {
  81. $form['account']['mail_confirm'] = array(
  82. '#type' => 'textfield',
  83. '#title' => t('Confirm e-mail address'),
  84. '#maxlength' => EMAIL_MAX_LENGTH,
  85. '#description' => t('Please confirm your e-mail address.'),
  86. '#required' => TRUE,
  87. );
  88. $form['#validate'][] = 'foo_user_register_form_validate';
  89. }
  90.  
  91. /**
  92. * Implements validation callback.
  93. */
  94. function foo_user_register_form_validate(&$form, &$form_state) {
  95. if ($form_state['values']['mail'] != $form_state['values']['mail_confirm']) {
  96. form_set_error('mail_confirm', 'The email addresses must match.');
  97. }
  98. }
Add Comment
Please, Sign In to add comment